2 c609673748 c609673748 于 2016.04.29 18:26 提问

tomcat7 log4j配置一部分日志还在catalina.out输出

我按照网上配置在tomcat配置了log4j,一部分日志是按我配置那样输出的,但是有一部分日志还是写入catalina.out,不知道为什么,我看了主要是线程调用的类输出的日志。
有谁知道原因吗?

步骤如下:
1. 把log4j-1.2.17.jar,tomcat-juli.jar,tomcat-juli-adapters.jar拷贝到tomcate目录/ lib下
2. 把tomcat-juli.jar拷贝到tomcate目录/ bin下,并覆盖原来的tomcat-juli.jar
3. 在tomcate目录/ lib下(例如/tomcat/apache-tomcat-7.0.59/lib)新建一个文件log4j.properties,并添加如下内容
log4j.rootLogger=INFO, CATALINA

Define all the appenders

log4j.appender.CATALINA=org.apache.log4j.RollingFileAppender
log4j.appender.CATALINA.File=${catalina.base}/logs/catalina.
log4j.appender.CATALINA.MaxFileSize=50MB
log4j.appender.CATALINA.MaxBackupIndex=100

log4j.appender.CATALINA.Append=true
log4j.appender.CATALINA.Encoding=GBK

Roll-over the log once per day

log4j.appender.CATALINA.DatePattern='.'yyyy-MM-dd-HH-mm'.log'
log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n

log4j.appender.LOCALHOST=org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOCALHOST.File=${catalina.base}/logs/localhost.
log4j.appender.LOCALHOST.Append=true
log4j.appender.LOCALHOST.Encoding=GBK
log4j.appender.LOCALHOST.DatePattern='.'yyyy-MM-dd-HH'.log'
log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
log4j.appender.LOCALHOST.layout.ConversionPattern = %d [%t] %-5p %c- %m%n

log4j.appender.MANAGER=org.apache.log4j.DailyRollingFileAppender
log4j.appender.MANAGER.File=${catalina.base}/logs/manager.
log4j.appender.MANAGER.Append=true
log4j.appender.MANAGER.Encoding=GBK
log4j.appender.MANAGER.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n

log4j.appender.HOST-MANAGER=org.apache.log4j.DailyRollingFileAppender
log4j.appender.HOST-MANAGER.File=${catalina.base}/logs/host-manager.
log4j.appender.HOST-MANAGER.Append=true
log4j.appender.HOST-MANAGER.Encoding=GBK
log4j.appender.HOST-MANAGER.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n

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

Configure which loggers log to which appenders

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=INFO, LOCALHOST
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]=\
INFO, MANAGER
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager]=\
INFO, HOST-MANAGER

  1. 在tomcate目录/ conf下(例如/tomcat/apache-tomcat-7.0.59/conf)打开context.xml,把修改为
  2. 删除 Tomcat 的/tomcat/apache-tomcat-7.0.59/conf/logging.properties 文件(或者重命名-建议)

2个回答

CSDNXIAON
CSDNXIAON   2016.04.29 18:32

tomcat下用Log4j 按文件大小,生成catalina.out日志文件
把system.out.println的内容用log4j输出到tomcat日志里方法
Tomcat下使用Log4j 接管 catalina.out 日志文件生成方式
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

devmiao
devmiao   Ds   Rxr 2016.05.01 13:25
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!