简体   繁体   English

在Linux环境中使用log4j进行日志轮换后,Tomcat无法登录到catalina.out

[英]Tomcat not logging to catalina.out after log rotation using log4j in linux Environment

I have used log4j to rotate catalina.out .After the first log rotation tomcat started logging to newly created file by log4j not to catalina.out in linux environment.Every thing works fine in windows environment. 我已经使用log4j旋转catalina.out。在第一次日志旋转tomcat开始通过log4j记录到新创建的文件后,而不是在Linux环境中记录到catalina.out。在Windows环境中一切正常。

Here's my log4j.properties 这是我的log4j.properties

log4j.rootLogger=ALL, file

log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/catalina.out
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[Java] %d{yyyy-MM-dd HH:mm:ss} - %5p - %c{1} : Line No. %L - %m%n
log4j.appender.file.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.FILE.Append=true

Please suggest. 请提出建议。

The catalina.out file is actually created by output redirection from the shell when you launch Tomcat using bin/catalina.sh and friends. 当您使用bin/catalina.sh和好友启动Tomcat时, catalina.out文件实际上是通过外壳程序的输出重定向创建的。 If you try to rotate that file using log4j, you will clobber that file with your log4j logs. 如果尝试使用log4j旋转该文件,则将用log4j日志破坏该文件。 tomcat is still logging to the old catalina.out, which no longer exists. tomcat仍在登录到不再存在的旧catalina.out。

You should point log4j at a different log file and not rotate catalina.out at all. 您应该将log4j指向另一个日志文件,而不要完全旋转catalina.out。 If you absolutely must rotate catalina.out, use another technique. 如果绝对必须旋转catalina.out,请使用另一种技术。

If your catalina.out is filling up with System.out.println garbage from applications, read about the swallowOutput option in Tomcat. 如果您的catalina.out充满了应用程序中的System.out.println垃圾,请阅读Tomcat中的swallowOutput选项。 That will capture System.out and System.err and redirect it to a file instead of dumping it to standard output. 这将捕获System.outSystem.err并将其重定向到文件,而不是将其转储到标准输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM