log4j使用示例

在使用的类中添加成员变量就可以。

private  Log logger = LogFactory.getLog(Hello.class);



# Configure logging for testing: optionally with log file
#log4j.rootLogger=WARN, stdout,A2
#log4j.rootLogger=INFO, stdout,A2
log4j.rootLogger=INFO, stdout
#the Word upon "WARN" is the level that log4j will output
#there are five levels can be used to control the log4j
# FATAL 0  ERROR  3  WARN   4  INFO  6  DEBUG 7
#the Word upon "stdout" represents the place where log4j will put

log4j.logger.com.opensymphony.xwork2.ognl.OgnlValueStack = ERROR
# log4j.rootLogger=WARN, stdout, logfile

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=target/spring.log
log4j.appender.logfile.append=false
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.appender.A2 = org.apache.log4j.RollingFileAppender
#log4j.appender.A2.File = logs\\test.log
#log4j.appender.A2.File =D\:\\test.log
log4j.appender.A2.File =D\:\\test.log
log4j.appender.A2.MaxFileSize = 1MB
log4j.appender.A2.MaxBackupIndex = 3
log4j.appender.A2.layout = org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern =[%d] %-4r [%t] %-5p %c %x - %m %n


猜你喜欢

转载自osacar.iteye.com/blog/1049335