Tomcat下catalina日志拆分
1.准备jar包
log4j-1.2.17.jar(从https://downloads.apache.org/logging/log4j/1.2.17/下载)
tomcat-juli.jar
tomcat-juli-adapters.jar(从https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/extras/下载,根据tomcat版本选择对应的分支)
8.0.53使用8.5和9.0版本的tomcat日志拆分
2.将上面的三个jar包拷贝到Tomcat的lib目录下
3.将tomcat-juli.jar拷贝到Tomcat的bin目录下,替换原有的jar包
4.修改Tomcat的conf/context.xml文件
xxx
增加swallowOutput="true"属性配置,可以把Tomcat的catalina.out日志接管过来
5.删除Tomcat的conf/logging.properties文件(或者重命名-建议书)
6.在Tomcat的lib目录下创建log4j.properties文件:
log4j.rootLogger=INFO, CATALINA
# Define all the appenders
log4j.appender.CATALINA=org.apache.log4j.RollingFileAppender
#log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.File=${catalina.base}/logs/catalina.out
log4j.appender.CATALINA.Append=true
log4j.appender.CATALINA.Encoding=UTF-8
# Roll-over the log once per day
#log4j.appender.CATALINA.DatePattern='.'yyyy-MM-dd'.log'
#log4j.appender.CATALINA.MaxFileSize=2MB
log4j.appender.CATALINA.MaxFileSize=20MB
# Archive log files (one backup file here)
log4j.appender.CATALINA.MaxBackupIndex=9999
log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
#log4j.appender.CATALINA.layout.ConversionPattern=%5p|%t | %c{1}-%M [%d{yyyy-MM-dd HH:mm:ss}] - %m%n
log4j.appender.CATALINA.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss}] - %m%n
#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=UTF-8
log4j.appender.LOCALHOST.DatePattern='.'yyyy-MM-dd'.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=UTF-8
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=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 [%t] %-5p %c- %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 [%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
7.重启Tomcat