Tomcat 6.0 Logger的配置

*author 谭剑

##################################################################################################################
在Apache官方网站上已声明,对于Tomcat6.0的版本,把<logger>元素嵌套在<Context>元素中不再合法.
原文如下:
An important consequence for Tomcat 6.0 is that the <Logger> element found in previous versions to create a localhost_log is no longer a valid nested element of <Context>. Instead, the default Tomcat configuration will use java.util.logging. If the developer wishes to collect detailed internal Tomcat logging (i.e what is happening within the Tomcat engine), then they should configure a logging system such as java.util.logging or log4j as detailed next.

详细见(http://tomcat.apache.org/tomcat-6.0-doc/logging.html).

但是要使用tomcat的logger也并非不可能,只是有点繁琐.


**  步骤如下:

1.下载log4j.jar(版本1.2.15, 大小3.51MB)
地址:http://www.apache.org/dist/logging/log4j/1.2.15/apache-log4j-1.2.15.zip

2.创建log4j.properties文件,内容如下:

(1)非官网的配置
#----------------------------------
log4j.rootLogger=ERROR,R

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

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.home}/logs/日志文件名.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=2
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[%p]%t-%c-%m%n

log4j.logger.org.apache.catalina=INFO,R,CONSOLE
#--------------------------------------

(2)官网的配置范例
#---------------------------------
log4j.rootLogger=debug, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.home}/logs/tomcat.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.logger.org.apache.catalina=DEBUG, R
#--------------------------------------


3.下载两个jar文件,分别是"tomcat-juli-adapters.jar(大小22.4KB)"和"tomcat-juli.jar(大小59.3KB)".
地址:http://www.apache.org/dist/tomcat/tomcat-6/v6.0.20/bin/extras/tomcat-juli-adapters.jar
地址:http://www.apache.org/dist/tomcat/tomcat-6/v6.0.20/bin/extras/tomcat-juli.jar


##################################################################################################################
**  具体操作步骤:
1.将[tomcat-juli-adapters.jar],[log4j-1.2.15.jar]和[log4j.properties]这三个文件放到 $CATALINA_HOME/lib下.
2.将[tomcat-juli.jar]放到 $CATALINA_HOME/bin下.

启动Tomcat,然后就可以在 $CATALINA_HOME/logs下看到名为XXX.log的日志文件了.

 

##################################################################################################################
**  附:Apache官方网站的英文说明:


1.Create a file called log4j.properties with the following content and save it into $CATALINA_HOME/lib.
  
             log4j.rootLogger=debug, R
            log4j.appender.R=org.apache.log4j.RollingFileAppender
            log4j.appender.R.File=${catalina.home}/logs/tomcat.log
            log4j.appender.R.MaxFileSize=10MB
            log4j.appender.R.MaxBackupIndex=10
            log4j.appender.R.layout=org.apache.log4j.PatternLayout
            log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
            log4j.logger.org.apache.catalina=DEBUG, R

2.Download Log4J (v1.2 or later) and place the log4j jar in $CATALINA_HOME/lib.
3.Build or download the additional logging components. See the extras components documentation for details.
4.Replace $CATALINA_HOME/bin/tomcat-juli.jar with output/extras/tomcat-juli.jar.
5.Place output/extras/tomcat-juli-adapters.jar in $CATALINA_HOME/lib.
6.Start Tomcat
##################################################################################################################

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值