<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaBeat &#187; Log4J</title>
	<atom:link href="http://www.javabeat.net/category/log4j/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Mon, 13 May 2013 20:10:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Basic steps to configure Log4j using xml and properties file</title>
		<link>http://www.javabeat.net/2008/07/baisc-steps-to-configure-log4j-using-xml-and-properties-file/</link>
		<comments>http://www.javabeat.net/2008/07/baisc-steps-to-configure-log4j-using-xml-and-properties-file/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 10:39:48 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[Log4J]]></category>
		<category><![CDATA[Log4j]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=149</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>This example demonstrated how to configure Log4j setup using the Properties file and XML file. These are the two most widely used techniques for configuring the Log4j for your application. But, in the recent days configuring with properties files are considered to be old technique and recommended using XML. This example program uses simple standalone [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><p>This example demonstrated how to configure <a href="http://logging.apache.org/log4j/1.2/" target="_blank"><strong><em>Log4j</em></strong></a> setup using the Properties file and <strong><em>XML file</em></strong>. These are the two most widely used techniques for configuring the <strong><em>Log4j</em></strong> for your application. But, in the recent days configuring with <strong><em>properties files</em></strong> are considered to be old technique and recommended using <strong><em>XML</em></strong>.</p>
<p>This example program uses simple standalone java program for running the example. But, in most of the project scenarios it will be used in the web application. However the configuration file will be the same.</p>
<p><span style="text-decoration: underline;"><strong>Books:</strong></span> <span style="color: #000000;">If you are looking to buy a good book for reading the Log4j for your project development, we would recommend the <a href="http://astore.amazon.com/javabeat-20/detail/1590594991" target="_blank">Pro Apache Log4j</a> and <a href="http://astore.amazon.com/javabeat-20/detail/1590594991" target="_blank">The Complete Log4j Manual</a>. Also you would consider reading the list of <a href="http://www.javabeat.net/java-books/">Java books</a> recommended.<br />
</span></p>
<p>If you are Java developer and would like to receive the daily updates on Java tips or techniques, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<h3><strong>Configure Log4j</strong></h3>
<h3>log4j.properties</h3>
<p>It is the traditional properties file for configuring the log4j mechanism. It is not used by most of the projects because of the XML configuration&#8217;s flexibility.</p>
<pre class="brush: java; title: ; notranslate">
# Set root logger level to DEBUG and its only appender
              to Appender1.
log4j.rootLogger=INFO, Appender1,Appender2

# Appender1 is set to be a ConsoleAppender.
log4j.appender.Appender1=org.apache.log4j.
                                ConsoleAppender
log4j.appender.Appender2=org.apache.log4j.
                              RollingFileAppender
log4j.appender.Appender2.File=sample.log

# Appender2 uses PatternLayout.
log4j.appender.Appender1.layout=org.apache.log4j.
                                       PatternLayout
log4j.appender.Appender1.layout.ConversionPattern=
                               %-4r [%t] %-5p %c %x - %m%n

log4j.appender.Appender2.layout=org.apache.log4j.
                                        PatternLayout
log4j.appender.Appender2.layout.ConversionPattern=
                                 %-4r [%t] %-5p %c %x - %m%n

</pre>
<h3>log4j.xml</h3>
<p>It is mostly used and recommended configuration for setting up the log4j mechanism.</p>
<pre class="brush: java; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!--&lt;span class=&quot;hiddenSpellError&quot; pre=&quot;&quot;--&gt;DOCTYPE log4j:configuration SYSTEM &quot;log4j.dtd&quot;&gt;

xmlns:log4j=
              &quot;http://jakarta.apache.org/log4j/&quot;
               debug=&quot;false&quot;&gt;

   &lt;appender name=&quot;consoleAppender&quot;
      class=&quot;org.apache.log4j.ConsoleAppender&quot;&gt;
      &lt;param name=&quot;Threshold&quot; value=&quot;INFO&quot; /&gt;
      &lt;layout class=&quot;org.apache.log4j.PatternLayout&quot;&gt;
         &lt;param name=&quot;ConversionPattern&quot; value=&quot;%d
             %-5p  [%c{1}] %m %n&quot; /&gt;
      &lt;/layout&gt;
   &lt;/appender&gt;

   &lt;appender name=&quot;fileAppender&quot;
           class=&quot;org.apache.log4j.RollingFileAppender&quot;&gt;
      &lt;param name=&quot;Threshold&quot; value=&quot;INFO&quot; /&gt;
      &lt;param name=&quot;File&quot; value=&quot;sample.log&quot;/&gt;
      &lt;layout class=&quot;org.apache.log4j.PatternLayout&quot;&gt;
         &lt;param name=&quot;ConversionPattern&quot; value=&quot;%d
                %-5p  [%c{1}] %m %n&quot; /&gt;
      &lt;/layout&gt;
   &lt;/appender&gt;

   &lt;logger name=&quot;javabeat.net.log4j&quot; additivity=&quot;false&quot; &gt;
      &lt;level value=&quot;INFO&quot; /&gt;
      &lt;appender-ref ref=&quot;consoleAppender&quot;/&gt;
      &lt;appender-ref ref=&quot;fileAppender&quot;/&gt;
   &lt;/logger&gt;

&lt;/log4j:configuration&gt;</pre>
<h3>Log4jPropertyTest.java</h3>
<pre class="brush: java; title: ; notranslate">
package javabeat.net.log4j;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 * source : www.javabeat.net
 */
public class Log4jPropertyTest {
    private static Logger logger = Logger.getLogger
               (Log4jPropertyTest.class);
    public static void main (String args[]){
        PropertyConfigurator.configure(&quot;log4j.properties&quot;);
        logger.info(&quot;Test Log&quot;);
    }
}</pre>
<h3>Log4jXmlTest.java</h3>
<pre class="brush: java; title: ; notranslate">
package javabeat.net.log4j;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

/**
 * source : www.javabeat.net
 */
public class Log4jXmlTest {
    private static Logger logger = Logger.getLogger
                (Log4jXmlTest.class);
    public static void main (String args[]){
        DOMConfigurator.configure(&quot;log4j.xml&quot;);
        logger.info(&quot;Test Log&quot;);
    }

}</pre>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2F2008%2F07%2Fbaisc-steps-to-configure-log4j-using-xml-and-properties-file%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/2008/07/baisc-steps-to-configure-log4j-using-xml-and-properties-file/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/2008/07/baisc-steps-to-configure-log4j-using-xml-and-properties-file/" data-count="vertical" data-text="Basic steps to configure Log4j using xml and properties file" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2008/07/baisc-steps-to-configure-log4j-using-xml-and-properties-file/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
