用log4j代替tomcat自身的log - allentemplar的技术专栏 - CS...

来源:百度文库 编辑:神马文学网 时间:2024/05/11 08:37:56
根据上一篇说的,如果想用log4j来详细的打印出 tomcat的log,用下面的方法可以做到
首先,将common-logging和log4j的包放入tomat/common/lib下
然后将log4j.properties文件放入tomcat/common/classes下
就可以了..
下面是log4j.properties的配置
#
# Configures Log4j as the Tomcat system logger
# to output info level messages into a rolling log file.
#
log4j.rootLogger=INFO, R
#
# To continue using the "catalina.out" file (which grows forever),
# comment out the above line and uncomment the next.
#
#log4j.rootLogger=DEBUG, A1
#
# Configuration for standard output ("catalina.out").
#
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
#
# Print the date in ISO 8601 format
#
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
#
# Configuration for a rolling log file ("tomcat.log").
#
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.DatePattern=‘.‘yyyy-MM-dd
#
# Edit the next line to point to your logs directory.
# The last part of the name is the log file name.
#
#log4j.appender.R.File=F:/tomcat/logs/tomcat.log
#log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R=org.apache.log4j.ConsoleAppender
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d %p [%c] - <%m>%n
#
# Print the date in ISO 8601 format
#
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
#
# Application logging options
#
#log4j.logger.org.apache=DEBUG
#log4j.logger.org.apache=INFO
#log4j.logger.org.apache.struts=DEBUG
#log4j.logger.org.apache.struts=INFO
如果想打印去文件,修改一下上面的文件(其实也就是去掉两行注释),我这个是打印到控制台的
这个文件如果看不懂的话,先面壁半小时