Friday, May 18, 2007

Log4j's configuration file


Log4J configuration file

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c - %m%n


Program














01 import org.apache.log4j.*;
02 public class LoggerTest {
03 
04   static String category = LoggerTest.class.getName();
05   static Logger logger = Logger.getLogger(category);
06   static {
07     PropertyConfigurator.configure("test.properties");
08   }
09 
10   public static void main(String args[]) {
11     logger.debug("Entering main");
12     System.out.println("Hello World");
13     try {
14       Thread.sleep(450);
15     catch(Exception e) {
16       System.out.println("caught Exception: " 
17           e.getMessage());
18     }
19     logger.debug("Exiting main");
20   }
21 




Java2html




Output:

0     [main] DEBUG LoggerTest - Entering main
453 [main] DEBUG LoggerTest - Exiting main




Discuss this post in the learning forum.



Note: This text was originally posted on my earlier blog at http://www.adaptivelearningonline.net


 


 



Commercial Links


No comments: