如果是b/s项目,并且项目中有spring,那使用Log4j是很简单的,在web.xml中配置以下内容即可.
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
同时保证/WEB-INF/中有log4j.properties文件。
文件内容:
#FATAL 0
#ERROR 3
#WARN 4
#INFO 6
#DEBUG 7
#log4j.rootLogger = [ level ] , appenderName, appenderName, ?
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.Rfile=org.apache.log4j.RollingFileAppender
log4j.appender.Rfile.File=log4j.log
log4j.appender.Rfile.MaxFileSize=100KB
log4j.appender.Rfile.MaxBackupIndex=1
log4j.appender.Rfile.layout=org.apache.log4j.PatternLayout
log4j.appender.Rfile.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n
log4j.appender.DRFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DRFile.File=D:/apache-tomcat-5.5.15/logs/log4j.log
Log4j.appender.DRFile.MaxFileSize=100KB
Log4j.appender.DRFile.MaxBackupIndex=1
log4j.appender.DRFile.Append=true
log4j.appender.DRFile.Threshold=INFO
log4j.appender.DRFile.layout=org.apache.log4j.PatternLayout
log4j.appender.DRFile.layout.ConversionPattern=[\u65e5\u5fd7\u4fe1\u606f] %d{ISO8601} - %p %c -%-4r [%t] %-5p %c %x - %m%n
log4j.rootLogger=error, stdout
log4j.logger.org.apache.axis.enterprise=fatal,stdout
log4j.logger.org.apache.struts=error,stdout
log4j.logger.com.test=debug