本文主要是介绍catalina.out日志按天输出,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Tomcat下使用Log4j 接管 catalina.out 日志文件生成方式,按天存放,解决catalina.out日志文件过大问题Tomcat下使用Log4j 接管 catalina.out 日志文件生成方式,按天存放,解决catalina.out日志文件过大问题
1. 准备jar包:
log4j-1.2.17.jar (从 http://www.apache.org/dist/logging/log4j/1.2.17/ 下载)
tomcat-juli.jar, tomcat-juli-adapters.jar (从 http://www.apache.org/dist/tomcat/tomcat-7/v7.0.52/bin/extras/ 下载,根据你的Tomcat版本选择对应的分支)
2. 将上面的三个jar包拷贝到 Tomcat 的 lib 目录下;
3. 将 tomcat-juli.jar 拷贝到 Tomcat 的 bin 目录下,替换原有的jar包;
4. 修改 Tomcat 的 conf/context.xml 文件,将<Context>为<Context swallowOutput="true">
(增加 swallowOutput="true" 的属性配置,只有这样才能完全的把tomcat的stdout给接管过来。这一步很关键 在官网及网上找了许多资料都没有提及。);
5. 删除 Tomcat 的 conf/logging.properties 文件(或者重命名-建议);
6. 在 Tomcat 的 lib 目录下创建 log4j.properties 文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | log4j.rootLogger=INFO, CATALINA # Define all the appenders log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender log4j.appender.CATALINA.File=${catalina.base} /logs/catalina . 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.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=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 # 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.out日志按天输出的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!