<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: log4j code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 06:17:38 GMT</pubDate>
    <description>DZone Snippets: log4j code</description>
    <item>
      <title>Java: log4j Initialization Example</title>
      <link>http://snippets.dzone.com/posts/show/4013</link>
      <description>// Initialization for Basic Console Output&lt;br /&gt;// Ref: http://logging.apache.org/log4j/docs/manual.html&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; import com.foo.Bar;&lt;br /&gt;&lt;br /&gt; // Import log4j classes.&lt;br /&gt; import org.apache.log4j.Logger;&lt;br /&gt; import org.apache.log4j.BasicConfigurator;&lt;br /&gt;&lt;br /&gt; public class MyApp {&lt;br /&gt;&lt;br /&gt;   // Define a static logger variable so that it references the&lt;br /&gt;   // Logger instance named "MyApp".&lt;br /&gt;   static Logger logger = Logger.getLogger(MyApp.class);&lt;br /&gt;&lt;br /&gt;   public static void main(String[] args) {&lt;br /&gt;&lt;br /&gt;     // Set up a simple configuration that logs on the console.&lt;br /&gt;     BasicConfigurator.configure();&lt;br /&gt;&lt;br /&gt;     logger.setLevel(Level.DEBUG); // optional if log4j.properties file not used&lt;br /&gt;     // Possible levels: TRACE, DEBUG, INFO, WARN, ERROR, and FATAL&lt;br /&gt;&lt;br /&gt;     logger.info("Entering application.");&lt;br /&gt;     Bar bar = new Bar();&lt;br /&gt;     bar.doIt();&lt;br /&gt;     logger.info("Exiting application.");&lt;br /&gt;   }&lt;br /&gt; }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 14 May 2007 09:44:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4013</guid>
      <author>thitiv (Thiti V. Sintopchai)</author>
    </item>
    <item>
      <title>Log4j 101</title>
      <link>http://snippets.dzone.com/posts/show/3857</link>
      <description>// Once you have included the Log4j jar into the classpath of your&lt;br /&gt;// application, you can use the following code within each class to&lt;br /&gt;// get a logger for that class. That is, all log messages issued from&lt;br /&gt;// within that class will be tagged with the classname to make it&lt;br /&gt;// easier to locate a problem. See my tutorial on Log4j,&lt;br /&gt;// Log4j in 30 Minutes or Less (http://www.johnmunsch.com/projects/Presentations/)&lt;br /&gt;// for a better introduction.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;private static Logger log = Logger.getLogger(&lt;class name&gt;.class);&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;// When you need to specify the location (or a different name) for &lt;br /&gt;// the log.properties file, you can set a specific System variable&lt;br /&gt;// which Log4j will be guaranteed to read as soon as any part of&lt;br /&gt;// your code tries to use it. You do that by passing the following&lt;br /&gt;// to the JVM as you start your Java application.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;-Dlog4j.configuration=file:&lt;path to log.properties file&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 23 Apr 2007 14:43:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3857</guid>
      <author>JohnMunsch (John Munsch)</author>
    </item>
    <item>
      <title>Configure log4j to log info level to xml file</title>
      <link>http://snippets.dzone.com/posts/show/3418</link>
      <description>&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; &lt;!-- log info level into log.xml --&gt;&lt;br /&gt; &lt;appender name="XMLOut" class="org.apache.log4j.FileAppender"&gt; &lt;br /&gt;        &lt;param name="File" value="log.xml"/&gt;  &lt;br /&gt;        &lt;param name="Threshold" value="info"/&gt; &lt;br /&gt;        &lt;layout class="org.apache.log4j.xml.XMLLayout"/&gt;&lt;br /&gt;    &lt;/appender&gt; &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 07 Feb 2007 06:20:25 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3418</guid>
      <author>vincente (vincente)</author>
    </item>
    <item>
      <title>log4j.properties: eclipse log4j HOWTO in 10 minutes</title>
      <link>http://snippets.dzone.com/posts/show/3248</link>
      <description>// How to use log4j within eclipse in 10 minutes&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# HOW TO USE LOG4J WITHIN ECLIPSE IN 10 MINUTES&lt;br /&gt;# by Daniel Gonzalez Gasull  gasull[at]gmail[dot]com&lt;br /&gt;#&lt;br /&gt;# 1) Download log4j http://logging.apache.org/site/binindex.cgi&lt;br /&gt;# 2) Unpack the .zip file in your Java folder (In Windows it is usually &lt;br /&gt;# C:\Program Files\Java\)&lt;br /&gt;# 3) In Eclipse: Window - Preferences... - Java - Build Path - User Libraries - &lt;br /&gt;# New - write "log4j" - OK - Add JARs... - navigate to find your log4j .jar you just&lt;br /&gt;# unpacked in the Java Folder - OK &lt;br /&gt;# 4) right click on your project in the Package Explorer - New - Folder - &lt;br /&gt;# in "Folder name" write "log4j" - click Advanced - select "Link to a folder in the&lt;br /&gt;# file system" - create a new folder "log4j" in your project folder in the file system&lt;br /&gt;# 5) Place this file you are reading right now in in the folder you just created.  Name&lt;br /&gt;# the file as log4j.properties&lt;br /&gt;# 6) In Eclipse: Run - Run... - In the navigation bar on the left select either the &lt;br /&gt;# server, or the runnable class, or the JUnit test you want to log with log4j -&lt;br /&gt;# select the Classpath tab - User Entries - Advanced... - Add folders - OK - select &lt;br /&gt;# the "log4j" folder you created in your project - OK   &lt;br /&gt;# 7) Repeat step 6 for other servers, runnable classes or JUnit tests you want to log&lt;br /&gt;# 8) Change in the following line the "org.example.foo.bar" with whatever you want.&lt;br /&gt;log4j.category.org.example.foo.bar=DEBUG&lt;br /&gt;# 9) Add the following import to the Java Class you want to log:&lt;br /&gt;#	import org.apache.log4j.Logger;&lt;br /&gt;# 10) Add this lines to the Java Class you want to log:&lt;br /&gt;#	/**&lt;br /&gt;#	 * Log4j logger&lt;br /&gt;#	 */&lt;br /&gt;#	static Logger log4j = Logger.getLogger("org.example.foo.bar");&lt;br /&gt;# 11) Substitute in the code above "org.example.foo.bar" with whatever your wrote in&lt;br /&gt;# in the step 8.&lt;br /&gt;# 12) Add something like the following code in your Class whenever you want to log:&lt;br /&gt;#	log4j.debug("WTF?");&lt;br /&gt;# 13) Repeat steps 9, 10, 11 and 12 for every Java Class you want to log&lt;br /&gt;# 14) Enjoy!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;log4j.rootCategory=DEBUG, R, O&lt;br /&gt;&lt;br /&gt;# Stdout&lt;br /&gt;log4j.appender.O=org.apache.log4j.ConsoleAppender&lt;br /&gt;&lt;br /&gt;# File&lt;br /&gt;log4j.appender.R=org.apache.log4j.RollingFileAppender&lt;br /&gt;log4j.appender.R.File=log4j.log&lt;br /&gt;&lt;br /&gt;# Control the maximum log file size&lt;br /&gt;log4j.appender.R.MaxFileSize=100KB&lt;br /&gt;&lt;br /&gt;# Archive log files (one backup file here)&lt;br /&gt;log4j.appender.R.MaxBackupIndex=1&lt;br /&gt;&lt;br /&gt;log4j.appender.R.layout=org.apache.log4j.PatternLayout&lt;br /&gt;log4j.appender.O.layout=org.apache.log4j.PatternLayout&lt;br /&gt;&lt;br /&gt;log4j.appender.R.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n&lt;br /&gt;log4j.appender.O.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n&lt;br /&gt;</description>
      <pubDate>Fri, 05 Jan 2007 16:28:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3248</guid>
      <author>dgasull (Daniel Gonz&#225;lez Gasull)</author>
    </item>
    <item>
      <title>Configure Log4J in a WebObjects app</title>
      <link>http://snippets.dzone.com/posts/show/163</link>
      <description>&lt;code&gt;(new DOMConfigurator()).doConfigure(resourceManager().inputStreamForResourceNamed("log4j.xml", "app", null), LogManager.getLoggerRepository());&lt;/code&gt;</description>
      <pubDate>Thu, 14 Apr 2005 04:06:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/163</guid>
      <author>rentzsch (Jonathan 'Wolf' Rentzsch)</author>
    </item>
  </channel>
</rss>
