<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohammad Faisal</title>
    <description>The latest articles on DEV Community by Mohammad Faisal (@faisal6621).</description>
    <link>https://dev.to/faisal6621</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F201246%2F2d4b6713-1dfb-49aa-be18-e3f452b1927c.jpg</url>
      <title>DEV Community: Mohammad Faisal</title>
      <link>https://dev.to/faisal6621</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/faisal6621"/>
    <language>en</language>
    <item>
      <title>GitLab - skip pipeline on push</title>
      <dc:creator>Mohammad Faisal</dc:creator>
      <pubDate>Wed, 28 Jul 2021 07:32:44 +0000</pubDate>
      <link>https://dev.to/faisal6621/gitlab-skip-pipeline-on-push-5acb</link>
      <guid>https://dev.to/faisal6621/gitlab-skip-pipeline-on-push-5acb</guid>
      <description>&lt;p&gt;If you have configured a GitLab &lt;a href="https://docs.gitlab.com/ee/ci/pipelines/" rel="noopener noreferrer"&gt;CI/CD pipeline&lt;/a&gt; well then on each &lt;code&gt;push&lt;/code&gt; to the repository result in execution of the pipeline. Sometimes it is not desirable to launch the pipeline immediately on the push or you may want to execute the pipeline using a &lt;a href="https://docs.gitlab.com/ee/ci/pipelines/schedules.html" rel="noopener noreferrer"&gt;schedule&lt;/a&gt;, in such case you can pass additional &lt;a href="https://git-scm.com/docs/git-push#Documentation/git-push.txt--oltoptiongt" rel="noopener noreferrer"&gt;push option&lt;/a&gt; to instruct GitLab to skip the pipeline execution. To do so, the command would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push -o ci.skip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But if you are using any &lt;a href="http://git-scm.com/downloads/guis/" rel="noopener noreferrer"&gt;GUI client&lt;/a&gt; for &lt;code&gt;git&lt;/code&gt; then you will not be able to pass this additional argument to the push command. In that case, you can configure the &lt;code&gt;push.pushOption&lt;/code&gt; instead as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --local --add push.pushOption ci.skip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;sup&gt;*&lt;/sup&gt; Make sure to remove this configuration when you no longer want to skip the pipeline on &lt;code&gt;push&lt;/code&gt;. To do so, use the &lt;code&gt;--unset&lt;/code&gt; option:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --local --unset push.pushOption
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you prefer git &lt;strong&gt;CLI&lt;/strong&gt; over &lt;strong&gt;GUI&lt;/strong&gt; then you can create alias for such case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --local --add alias.skipPipeline "push -o ci.skip"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you have choice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;to skip pipeline use command: &lt;code&gt;git skipPipeline&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;normal push with pipeline execution: &lt;code&gt;git push&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope you may find this information useful. Feel free to leave your feedback/opinion in comments.&lt;/p&gt;

</description>
      <category>git</category>
      <category>gitlab</category>
      <category>pipeline</category>
      <category>cicd</category>
    </item>
    <item>
      <title>Find and remove docker image</title>
      <dc:creator>Mohammad Faisal</dc:creator>
      <pubDate>Wed, 10 Feb 2021 17:15:13 +0000</pubDate>
      <link>https://dev.to/faisal6621/find-and-remove-docker-image-1n5b</link>
      <guid>https://dev.to/faisal6621/find-and-remove-docker-image-1n5b</guid>
      <description>&lt;p&gt;Docker documentation mentions &lt;a href="https://docs.docker.com/engine/reference/commandline/rm/#remove-all-stopped-containers" rel="noopener noreferrer"&gt;removing all stopped containers&lt;/a&gt; using command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;docker ps &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-q&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but at times we want to first find existing containers and then remove them. This can be achieved when you filter and limit the result of &lt;code&gt;docker ps&lt;/code&gt; command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limit the result of &lt;code&gt;docker ps&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;You can either use the &lt;a href="https://docs.docker.com/engine/reference/commandline/ps/#filtering" rel="noopener noreferrer"&gt;&lt;code&gt;--filter&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://docs.docker.com/engine/reference/commandline/ps/#options" rel="noopener noreferrer"&gt;&lt;code&gt;--last&lt;/code&gt;&lt;/a&gt; or &lt;a href="https://docs.docker.com/engine/reference/commandline/ps/#options" rel="noopener noreferrer"&gt;&lt;code&gt;--latest&lt;/code&gt;&lt;/a&gt; options or pipe the result of &lt;code&gt;docker ps&lt;/code&gt; to &lt;code&gt;grep&lt;/code&gt; command to filter the results for matching &lt;em&gt;PATTERN&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Here is an example using &lt;code&gt;grep&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker ps &lt;span class="nt"&gt;-a&lt;/span&gt; | &lt;span class="nb"&gt;grep &lt;/span&gt;PATTERN | &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'{print $1}'&lt;/span&gt; | xargs &lt;span class="nt"&gt;-r&lt;/span&gt; docker &lt;span class="nb"&gt;rm&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where the &lt;em&gt;PATTERN&lt;/em&gt; could be part of container name, image name or any other details present in the result of &lt;code&gt;docker ps&lt;/code&gt; command like mapped port number.&lt;/p&gt;

&lt;p&gt;Feel free to share your feedback/opinion in comments.&lt;/p&gt;




&lt;p&gt;&lt;span&gt;Photo by &lt;a href="https://unsplash.com/@boxedwater?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Boxed Water Is Better&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/ocean?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
    </item>
    <item>
      <title>Solving CWE-606: Unchecked Input for Loop Condition</title>
      <dc:creator>Mohammad Faisal</dc:creator>
      <pubDate>Mon, 11 May 2020 15:12:55 +0000</pubDate>
      <link>https://dev.to/faisal6621/solving-cwe-606-unchecked-input-for-loop-condition-184e</link>
      <guid>https://dev.to/faisal6621/solving-cwe-606-unchecked-input-for-loop-condition-184e</guid>
      <description>&lt;p&gt;The &lt;strong&gt;&lt;a href="https://cwe.mitre.org/data/definitions/606.html" rel="noopener noreferrer"&gt;CWE-606: Unchecked Input for Loop Condition&lt;/a&gt;&lt;/strong&gt; is described as:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The product does not properly check inputs that are used for loop conditions, potentially leading to a &lt;em&gt;&lt;strong&gt;denial of service because of excessive looping&lt;/strong&gt;&lt;/em&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;with an attached demonstrative example in &lt;code&gt;C&lt;/code&gt; as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;iterate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="n"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;iterateFoo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;scanf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%u"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;iterate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Recently I came across this issue in my Java application when we scanned the project with &lt;a href="https://www.checkmarx.com/products/static-application-security-testing" rel="noopener noreferrer"&gt;Checkmarx's CxSAST&lt;/a&gt;. The code is something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;records&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt; &lt;span class="c1"&gt;// The records are read from a received file&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;records&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++){&lt;/span&gt;
  &lt;span class="c1"&gt;// some processing here&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now in order to solve this issue I identify two approaches:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;define a max size of records and compare the size of the records to that value and if it is greater than that then either do not process any record and exit or process the records in chunks by splitting them by the max size.&lt;/li&gt;
&lt;li&gt;rewrite this &lt;em&gt;for-loop&lt;/em&gt; as &lt;em&gt;for-each&lt;/em&gt; which do not check for the execution condition and process until it has record in there.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the 1st solution it would be difficult to put a size restriction as we do not know the limit of number of records could be there and we have to process them all. If we go by a chunk processing then we could put some arbitrary value.&lt;/p&gt;

&lt;p&gt;In the 2nd solution we may trick the checkmarx that we have not used the user input as loop condition but I am not sure if that will work or not?&lt;/p&gt;

&lt;p&gt;What is your opinion on this?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>cwe</category>
      <category>security</category>
    </item>
    <item>
      <title>Spring batch - changing default data-source</title>
      <dc:creator>Mohammad Faisal</dc:creator>
      <pubDate>Fri, 24 Jan 2020 05:51:33 +0000</pubDate>
      <link>https://dev.to/faisal6621/spring-batch-changing-default-data-source-3e24</link>
      <guid>https://dev.to/faisal6621/spring-batch-changing-default-data-source-3e24</guid>
      <description>&lt;p&gt;I had recently started learning &lt;a href="https://spring.io/projects/spring-batch" rel="noopener noreferrer"&gt;Spring-Batch&lt;/a&gt; and followed the very first Getting started &lt;a href="https://spring.io/guides/gs/batch-processing/" rel="noopener noreferrer"&gt;guide&lt;/a&gt;.&lt;br&gt;
The default datasource used by Spring-batch is HSQL as an in-memory database, good enough for local development. But you may not only use that in production code. You can change that datasource to yours with the following configurations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="py"&gt;spring.datasource.url&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;jdbc:url:for-your-database&amp;gt;&lt;/span&gt;
&lt;span class="py"&gt;spring.datasource.username&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;db-username&amp;gt;&lt;/span&gt;
&lt;span class="py"&gt;spring.datasource.password&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;db-password&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All &lt;code&gt;spring.datasource.*&lt;/code&gt; properties are bound to the fields of &lt;code&gt;org.springframework.boot.autoconfigure.jdbc.DataSourceProperties&lt;/code&gt; class. &lt;/p&gt;

</description>
      <category>spring</category>
      <category>batch</category>
      <category>java</category>
    </item>
    <item>
      <title>Missing draft post</title>
      <dc:creator>Mohammad Faisal</dc:creator>
      <pubDate>Fri, 24 Jan 2020 02:38:12 +0000</pubDate>
      <link>https://dev.to/faisal6621/missing-draft-post-5891</link>
      <guid>https://dev.to/faisal6621/missing-draft-post-5891</guid>
      <description>&lt;p&gt;I had recently created a post and saved that as draft. I can no longer find that in my profile. Where does the draft posts goes? &lt;/p&gt;

</description>
      <category>help</category>
    </item>
    <item>
      <title>Minimum Configuration for log4j</title>
      <dc:creator>Mohammad Faisal</dc:creator>
      <pubDate>Wed, 08 Jan 2020 17:37:31 +0000</pubDate>
      <link>https://dev.to/faisal6621/minimum-configuration-for-log4j-20jf</link>
      <guid>https://dev.to/faisal6621/minimum-configuration-for-log4j-20jf</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;No appenders could be found for logger(log4j)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You may have encountered this issue with many applications (hibernate, spring, etc.) when trying to run a Java program from command line.&lt;br&gt;
The error appears in console something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nl"&gt;log4j:&lt;/span&gt;&lt;span class="no"&gt;ERROR&lt;/span&gt; &lt;span class="nc"&gt;Could&lt;/span&gt; &lt;span class="n"&gt;not&lt;/span&gt; &lt;span class="n"&gt;find&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="n"&gt;log4j&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;appender&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;CONSOLE&lt;/span&gt;
&lt;span class="nl"&gt;log4j:&lt;/span&gt;&lt;span class="no"&gt;ERROR&lt;/span&gt; &lt;span class="nc"&gt;Could&lt;/span&gt; &lt;span class="n"&gt;not&lt;/span&gt; &lt;span class="n"&gt;instantiate&lt;/span&gt; &lt;span class="n"&gt;appender&lt;/span&gt; &lt;span class="n"&gt;named&lt;/span&gt; &lt;span class="s"&gt;"CONSOLE"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;

&lt;span class="nl"&gt;log4j:&lt;/span&gt;&lt;span class="no"&gt;WARN&lt;/span&gt; &lt;span class="nc"&gt;No&lt;/span&gt; &lt;span class="n"&gt;appenders&lt;/span&gt; &lt;span class="n"&gt;could&lt;/span&gt; &lt;span class="n"&gt;be&lt;/span&gt; &lt;span class="n"&gt;found&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nf"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;company&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ClassName&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;
&lt;span class="nl"&gt;log4j:&lt;/span&gt;&lt;span class="no"&gt;WARN&lt;/span&gt; &lt;span class="nc"&gt;Please&lt;/span&gt; &lt;span class="n"&gt;initialize&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;log4j&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt; &lt;span class="n"&gt;properly&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
&lt;span class="nl"&gt;log4j:&lt;/span&gt;&lt;span class="no"&gt;WARN&lt;/span&gt; &lt;span class="nc"&gt;See&lt;/span&gt; &lt;span class="nl"&gt;http:&lt;/span&gt;&lt;span class="c1"&gt;//logging.apache.org/log4j/1.2/faq.html#noconfig for more info.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the warning says itself: &lt;code&gt;Please initialize the log4j system properly&lt;/code&gt;, you must check when running the program did the &lt;code&gt;log4j.properties&lt;/code&gt; or &lt;code&gt;log4j.xml&lt;/code&gt; is available on the &lt;em&gt;classpath&lt;/em&gt; or either one of them do really exists?&lt;/p&gt;

&lt;h4&gt;
  
  
  A minimum configuration would be
&lt;/h4&gt;

&lt;h5&gt;
  
  
  log4j.properties
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="c"&gt;# Set root logger level to DEBUG and its only appender to CONSOLE.
&lt;/span&gt;&lt;span class="py"&gt;log4j.rootLogger&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;DEBUG, CONSOLE&lt;/span&gt;

&lt;span class="c"&gt;# CONSOLE appender is set to be a ConsoleAppender.
&lt;/span&gt;&lt;span class="py"&gt;log4j.appender.CONSOLE&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;org.apache.log4j.ConsoleAppender&lt;/span&gt;

&lt;span class="c"&gt;# CONSOLE appender uses PatternLayout.
&lt;/span&gt;&lt;span class="py"&gt;log4j.appender.CONSOLE.layout&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;org.apache.log4j.PatternLayout&lt;/span&gt;
&lt;span class="py"&gt;log4j.appender.CONSOLE.layout.ConversionPattern&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;%-4r [%t] %-5p %c %x - %m%n&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  log4j.xml
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;log4j:configuration&lt;/span&gt; &lt;span class="na"&gt;debug=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt; &lt;span class="na"&gt;xmlns:log4j=&lt;/span&gt;&lt;span class="s"&gt;'http://jakarta.apache.org/log4j/'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;appender&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"console"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"org.apache.log4j.ConsoleAppender"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;param&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Target"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"System.out"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;layout&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"org.apache.log4j.PatternLayout"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;param&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"ConversionPattern"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/layout&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/appender&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;root&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;priority&lt;/span&gt; &lt;span class="na"&gt;value =&lt;/span&gt;&lt;span class="s"&gt;"debug"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/priority&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;appender-ref&lt;/span&gt; &lt;span class="na"&gt;ref=&lt;/span&gt;&lt;span class="s"&gt;"console"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/appender&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/root&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/log4j:configuration&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can name anything for the appender name which I had chosen &lt;code&gt;CONSOLE&lt;/code&gt;/&lt;code&gt;console&lt;/code&gt; as this is more relevant if you want to see the logs in console rather than appended in some file. &lt;/p&gt;

&lt;h2&gt;
  
  
  Application specific log configuration
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="py"&gt;log4j.logger.domain.company.name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;LOG_LEVEL&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>log4j</category>
      <category>java</category>
    </item>
  </channel>
</rss>
