不想给linux安装插件切割,只想tomcat解决
官方文档参考:https://tomcat.apache.org/tomcat-8.0-doc/logging.html
上面链接有说明怎么用
下方为使用方法找到你的tomcat对应版本
下载地址为:https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/extras/
替换掉你本地版本去找下载即可,我的版本是v8.0.53,所以直接改上面版本下载即可
下载tomcat-juli-adapters.jar和tomcat-juli.jar
将tomcat-juli-adapters放到 tomcat目录\lib下
将tomcat-juli放到 tomcat目录\bin下 (切记 切记 切记 是bin目录下)
然后下载log4j的包
下载地址:https://mvnrepository.com/artifact/log4j/log4j
我用的版本是:log4j-1.2.17.jar
将log4j-1.2.17.jar拷贝到 tomcat目录\lib下
删除tomcat本身的logging.properties (在tomcat目录\conf 下面)
创建log4j.properties文件,将文件放到tomcat目录\lib下(注意:不是conf下面)
log4j.rootLogger=INFO, CATALINA,LOCALHOST,MANAGER,HOST-MANAGER
# Define all the appenders
log4j.appender.CATALINA=org.apache.log4j.RollingFileAppender
log4j.appender.CATALINA.File=${catalina.base}/logs/catalinas.out
log4j.appender.CATALINA.MaxFileSize=10240KB
log4j.appender.CATALINA.MaxBackupIndex=100
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-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.RollingFileAppender
log4j.appender.LOCALHOST.File=${catalina.base}/logs/localhost.log
log4j.appender.LOCALHOST.MaxFileSize=10240KB
log4j.appender.LOCALHOST.MaxBackupIndex=100
log4j.appender.LOCALHOST.Append=true
log4j.appender.LOCALHOST.Encoding=UTF-8
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.RollingFileAppender
log4j.appender.MANAGER.File=${catalina.base}/logs/manager.log
log4j.appender.MANAGER.MaxFileSize=10240KB
log4j.appender.MANAGER.MaxBackupIndex=100
log4j.appender.MANAGER.Append=true
log4j.appender.MANAGER.Encoding=UTF-8
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.RollingFileAppender
log4j.appender.HOST-MANAGER.File=${catalina.base}/logs/host-manager.log
log4j.appender.HOST-MANAGER.MaxFileSize=10240KB
log4j.appender.HOST-MANAGER.MaxBackupIndex=100
log4j.appender.HOST-MANAGER.Append=true
log4j.appender.HOST-MANAGER.Encoding=UTF-8
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
目录结构图:
还需要注意:注释掉catalina.sh里面的这一行
if [ -z "$CATALINA_OUT" ] ; then
#CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
CATALINA_OUT=/dev/null
fi