log4j 常用配置代码

Reference library:
  commons-logging-1.1.1.jar
  log4j-1.2.16.jar
Log Levels:
  DEBUG < INFO < WARN < ERROR < FATAL
log4j 配置说明
  http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html
log4j ConversionPattern 说明
  http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html
 
1. 将日志输出到 Console

# log4j.properties
# 将日志输出到 Console
log4j.rootLogger=DEBUG,console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%d] %-5p %C%n%m%n

 

2. 将日志记录到 File

# log4j.properties
# 将日志记录到 File
LOG_DIR=D:/log/demo

log4j.logger.org.demo=DEBUG,A1
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=${LOG_DIR}/demo.log
log4j.appender.A1.MaxFileSize=1MB
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[%d] %-5p %C%n%m%n

log4j.logger.org.demo.tmp.sub=DEBUG,A2
log4j.additivity.org.demo.tmp.sub=false
log4j.appender.A2=org.apache.log4j.RollingFileAppender
log4j.appender.A2.File=${LOG_DIR}/demo.tmp.log
log4j.appender.A2.MaxFileSize=1MB
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=[%d] %-5p %C%n%m%n

 

3. END

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