2016-09-08 83 views
0

我使用log4j版本2作爲Tomcat 8的記錄器,現在問題是catalina.out文件沒有每日輪轉。我的log4j.property文件如下,Log4J與Tomcat的集成 - catalina.out日誌文件輪換

log4j.rootLogger = INFO, CATALINA, CONSOLE 

# 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.DailyRollingFileAppender 
log4j.appender.CONSOLE.File = ${catalina.base}/logs/catalina.out 
log4j.appender.CONSOLE.Append = true 
log4j.appender.CONSOLE.Encoding = UTF-8 
log4j.appender.CONSOLE.DatePattern = '.'yyyy-MM-dd'.log' 
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 

我改變了這一行

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

log4j.appender.CONSOLE = org.apache.log4j.DailyRollingFileAppender 
log4j.appender.CONSOLE.File = ${catalina.base}/logs/catalina.out 
log4j.appender.CONSOLE.Append = true 
log4j.appender.CONSOLE.Encoding = UTF-8 
log4j.appender.CONSOLE.DatePattern = '.'yyyy-MM-dd'.log' 
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout 
log4j.appender.CONSOLE.layout.ConversionPattern = %d [%t] %-5p %c- %m%n 

正如奧古斯丁ghauratto在this link中所建議的那樣。但它不適合我。

我該如何讓catalina.out文件每天分裂並製作新文件。

回答

0

您誤解了如何創建catalina.out。它不是由log4j之類的日誌框架處理的。它是由shell通過重定向標準輸出流創建的。

如果要旋轉它,請檢查Tomcat FAQ

還有this previous answer