我使用log4j RollingFileAppender根据文件大小滚动日志文件。我们设置的最大文件大小是“10 MB”。它在tomcat 6中工作正常,但是当我们迁移到TomEE Plus时,日志文件不会发生......文件大小不断增长。
log4j配置如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<!-- Not needed for Production -->
<appender name="CA" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="DEBUG" />
<param name="encoding" value="UTF-8" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
</layout>
</appender>
<!-- Appender to log Gateway information messages -->
<appender name="FA_GATEWAY_INFO" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${gateway.logs}/logs/freshgate_info.log" />
<param name="encoding" value="UTF-8" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="25" />
<param name="Threshold" value="INFO" />
<layout class="org.apache.log4j.PatternLayout">
<!-- For production use this -->
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
<!-- For Development use this pattern -->
<!-- <param name="ConversionPattern" value="%m%n" /> <param name="ConversionPattern"
value="%-4r [%t] %-5p %c %x - %m%n" /> -->
</layout>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="DEBUG" />
<param name="AcceptOnMatch" value="false" />
</filter>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="WARN" />
<param name="AcceptOnMatch" value="false" />
</filter>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="ERROR" />
<param name="AcceptOnMatch" value="false" />
</filter>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="FATAL" />
<param name="AcceptOnMatch" value="false" />
</filter>
</appender>
<!-- Appender to log Gateway information messages -->
<appender name="FA_GATEWAY_DEBUG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${gateway.logs}/logs/freshgate_debug.log" />
<param name="encoding" value="UTF-8" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="25" />
<param name="Threshold" value="DEBUG" />
<layout class="org.apache.log4j.PatternLayout">
<!-- For production use this -->
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
<!-- For Development use this pattern -->
<!-- <param name="ConversionPattern" value="%m%n" /> <param name="ConversionPattern"
value="%-4r [%t] %-5p %c %x - %m%n" /> -->
</layout>
</appender>
<!-- Appender to log bC scale command messages -->
<appender name="FA_BC_SCALE_COMMAND_DEBUG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${gateway.logs}/logs/bc_scale_command_debug.log" />
<param name="encoding" value="UTF-8" />
<param name="MaxFileSize" value="5MB" />
<param name="MaxBackupIndex" value="25" />
<param name="Threshold" value="DEBUG" />
<layout class="org.apache.log4j.PatternLayout">
<!-- For production use this -->
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
<!-- For Development use this pattern -->
<!-- <param name="ConversionPattern" value="%m%n" /> <param name="ConversionPattern"
value="%-4r [%t] %-5p %c %x - %m%n" /> -->
</layout>
</appender>
<!-- Appender to log Gateway error messages -->
<appender name="FA_GATEWAY_ERROR" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${gateway.logs}/logs/freshgate_error.log" />
<param name="encoding" value="UTF-8" />
<param name="Threshold" value="ERROR" />
<param name="MaxFileSize" value="1MB" />
<param name="MaxBackupIndex" value="5" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
</layout>
</appender>
<logger name="com.mt.gw">
<level value="DEBUG" />
<appender-ref ref="FA_GATEWAY_DEBUG" />
<appender-ref ref="FA_GATEWAY_INFO" />
<appender-ref ref="FA_GATEWAY_ERROR" />
</logger>
<logger name="BcScaleCommandLogger">
<level value="DEBUG" />
<appender-ref ref="FA_BC_SCALE_COMMAND_DEBUG" />
</logger>
<!-- Blocks the hibernate table creation logs -->
<logger name="com.mt.gw.core.bl.persistence">
<level value="INFO" />
</logger>
<!-- Blocks hibernate logs -->
<logger name="org.hibernate">
<level value="ERROR" />
</logger>
<!-- Blocks both Struts and Catalina logs -->
<logger name="org.apache">
<level value="ERROR" />
</logger>
<!-- Blocks c3po connection pooling log messages -->
<logger name="com.mchange">
<level value="ERROR" />
</logger>
<!-- Blocks Quartz Scheduler logs -->
<logger name="org.quartz">
<level value="ERROR" />
</logger>
<!-- Not needed for Production -->
<root>
<level value="DEBUG" />
<appender-ref ref="CA" />
</root>
<!-- Appender to log bC TAF messages -->
<appender name="FA_BC_TAF_DEBUG_LOGGER" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${gateway.logs}/logs/bc_taf_debug.log" />
<param name="encoding" value="UTF-8" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="25" />
<param name="Threshold" value="DEBUG" />
<layout class="org.apache.log4j.PatternLayout">
<!-- For production use this -->
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
<!-- For Development use this pattern -->
<!-- <param name="ConversionPattern" value="%m%n" /> <param name="ConversionPattern"
value="%-4r [%t] %-5p %c %x - %m%n" /> -->
</layout>
</appender>
<logger name="BcTafLogger">
<level value="DEBUG" />
<appender-ref ref="FA_BC_TAF_DEBUG_LOGGER" />
</logger>
<appender name="FA_TAF_LOGGER_DEBUG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${gateway.logs}/logs/taf_debug.log" />
<param name="encoding" value="UTF-8" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="25" />
<param name="Threshold" value="DEBUG" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
</layout>
</appender>
<appender name="FA_TAF_LOGGER_ERROR" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${gateway.logs}/logs/taf_error.log" />
<param name="encoding" value="UTF-8" />
<param name="Threshold" value="ERROR" />
<param name="MaxFileSize" value="1MB" />
<param name="MaxBackupIndex" value="5" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
</layout>
</appender>
<logger name="TafLogger">
<level value="DEBUG" />
<appender-ref ref="FA_TAF_LOGGER_DEBUG" />
<appender-ref ref="FA_TAF_LOGGER_ERROR" />
</logger>
<appender name="FA_MANAGER_ERROR" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${gateway.logs}/logs/manager_error.log" />
<param name="encoding" value="UTF-8" />
<param name="Threshold" value="ERROR" />
<param name="MaxFileSize" value="1MB" />
<param name="MaxBackupIndex" value="5" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
</layout>
</appender>
<!-- Appender to log Gateway manager messages -->
<appender name="FA_GATEWAY_MANAGER" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${gateway.logs}/logs/manager.log" />
<param name="encoding" value="UTF-8" />
<param name="Threshold" value="INFO" />
<param name="MaxFileSize" value="5MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
</layout>
</appender>
<appender name="FA_GATEWAY_MANAGER_DEBUG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${gateway.logs}/logs/manager_debug.log" />
<param name="encoding" value="UTF-8" />
<param name="Threshold" value="DEBUG" />
<param name="MaxFileSize" value="5MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
</layout>
</appender>
<logger name="com.mt.manager">
<level value="DEBUG" />
<appender-ref ref="FA_GATEWAY_MANAGER_DEBUG" />
<appender-ref ref="FA_GATEWAY_MANAGER" />
<appender-ref ref="FA_MANAGER_ERROR" />
</logger>
<appender name="FA_ACTIVEMQ" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${gateway.logs}/logs/activemq.log" />
<param name="encoding" value="UTF-8" />
<param name="Threshold" value="ERROR" />
<param name="MaxFileSize" value="1MB" />
<param name="MaxBackupIndex" value="5" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
</layout>
</appender>
<logger name="org.apache.activemq">
<level value="ERROR" />
<appender-ref ref="FA_ACTIVEMQ" />
</logger>
</log4j:configuration>
答案 0 :(得分:0)
我已经通过将log4j.xml分成两个单独的配置来解决了这个问题。这解决了我的问题。