Tomcat中全局性的日志配置

如果我们在production环境中有许多web application, 一般来说我们都是每个application会有一个自己的log配置, 这样的话,可能就会有很多个log4j.properties. 而且production和development环境下的log4j.properties又不一样, 这样的话我们就需要维护很多个log4j配置文件. 在jboss中我们一般可以修改conf/log4j.xml来配置所有web应用的log. 但是tomcat默认是不支持log4j的. 但是对tomcat进行一些配置之后的话就可以实现跟jboss中一样的效果.

Tomcat5.x中.

1. 把你写好的log4j.properties(或者log4j.xml)移到$CATALINA_HOME/common/classes中.

2. 拷贝一份最新的log4j lib到$CATALINA_HOME/common/lib中.

3. 拷贝一份最新的commons log(commons-logging-x.y.z.jar而不是commons-logging-api-x.y.z.jar)到$CATALINA_HOME/common/lib中.

4. remove掉你web application中所有的log4j.xml文件和初始话log4j的代码(如果有的话).

5. OK. restart tomcat.


参考: http://tomcat.apache.org/tomcat-5.5-doc/logging.html

tomcat6请看. http://tomcat.apache.org/tomcat-6.0-doc/logging.html

猜你喜欢

转载自dengyin2000.iteye.com/blog/446228
今日推荐