log4j使用实例

log4j.rootLogger=DEBUG, A1 , R , file
log4j.appender.A1=org.apache.log4j.ConsoleAppender 
log4j.appender.A1.layout=org.apache.log4j.PatternLayout 
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n



log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=log/log4jdebug.log
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n



log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=2
log4j.appender.file.File=log/log4jdebug.html
log4j.appender.file.layout=org.apache.log4j.HTMLLayout





package com.test;





import org.apache.log4j.Level;
import org.apache.log4j.Logger;

public class TestLog {

 /**
  * @param args
  */
 private static Logger logger = Logger.getLogger(TestLog.class);
 public static void main(String[] args) {
  TestLog.logger.setLevel(Level.ALL);

  TestLog.logger.info("info");      
  TestLog.logger.debug("debug");
  TestLog.logger.fatal("fatal");

  
  
 }

}

 
2010-07-20 14:23:10 [com.test.TestLog]-[INFO] info 2010-07-20 14:23:10 [com.test.TestLog]-[DEBUG] debug 2010-07-20 14:23:10 [com.test.TestLog]-[FATAL] fatal

 

你可能感兴趣的:(apache,C++,c,log4j,C#)