tomcat8/9集成log4j

1、下载tomcat8.0.53 中的插件tomcat-juli.jar和tomcat-juli-adapters.jar两个jar把,经过测试,这两个jar适用于tomcat8.0、8.5、9.0
2、下载log4j-1.2.17.jar
3、将这三个jar拷贝到tomcat/lib目录下
4、将tomcat-juli.jar覆盖到tomcat/bin目录下
5、删除tomcat/conf下logging.properties文件
6、在tomcat/lib目录下创建log4j.properties文件,内容如下:
log4j.rootLogger=INFO,CATALINA,CONSOLE

# Define all the appenders
log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.File=${catalina.base}/logs/catalina.log
log4j.appender.CATALINA.Append=true
log4j.appender.CATALINA.Encoding=UTF-8
log4j.appender.CATALINA.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
log4j.appender.CATALINA.layout.ConversionPattern =%d{yyyy-MM-dd HH:mm:ss,SSS}#%p#%t#%c#%C{1}#%F#%M#%L#%r#%m%n

log4j.appender.LOCALHOST=org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOCALHOST.File=${catalina.base}/logs/localhost.log
log4j.appender.LOCALHOST.Append=true
log4j.appender.LOCALHOST.Encoding=UTF-8
log4j.appender.LOCALHOST.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
log4j.appender.LOCALHOST.layout.ConversionPattern =%d{yyyy-MM-dd HH:mm:ss,SSS}#%p#%t#%c#%C{1}#%F#%M#%L#%r#%m%n

log4j.appender.MANAGER=org.apache.log4j.DailyRollingFileAppender
log4j.appender.MANAGER.File=${catalina.base}/logs/manager.log
log4j.appender.MANAGER.Append=true
log4j.appender.MANAGER.Encoding=UTF-8
log4j.appender.MANAGER.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.MANAGER.layout.ConversionPattern =%d{yyyy-MM-dd HH:mm:ss,SSS}#%p#%t#%c#%C{1}#%F#%M#%L#%r#%m%n

log4j.appender.EXAMPLES=org.apache.log4j.DailyRollingFileAppender
log4j.appender.EXAMPLES.File=${catalina.base}/logs/examples.log
log4j.appender.EXAMPLES.Append=true
log4j.appender.EXAMPLES.Encoding=UTF-8
log4j.appender.EXAMPLES.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.EXAMPLES.layout = org.apache.log4j.PatternLayout
log4j.appender.EXAMPLES.layout.ConversionPattern =%d{yyyy-MM-dd HH:mm:ss,SSS}#%p#%t#%c#%C{1}#%F#%M#%L#%r#%m%n

log4j.appender.HOST-MANAGER=org.apache.log4j.DailyRollingFileAppender
log4j.appender.HOST-MANAGER.File=${catalina.base}/logs/host-manager.log
log4j.appender.HOST-MANAGER.Append=true
log4j.appender.HOST-MANAGER.Encoding=UTF-8
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{yyyy-MM-dd HH:mm:ss,SSS}#%p#%t#%c#%C{1}#%F#%M#%L#%r#%m%n

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Encoding=UTF-8
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern =%d{yyyy-MM-dd HH:mm:ss,SSS}#%p#%t#%c#%C{1}#%F#%M#%L#%r#%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].[/examples]=INFO,EXAMPLES
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
 

相关推荐