我目前正在使用log4j2为我的Web应用程序编写日志。我已经配置了一个滚动文件追加器,每晚午夜滚动。
我的log4j2.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %c{36} - %msg%n"/>
</Console>
<RollingFile
name="ApplicationLog"
fileName="${sys:catalina.base}/logs/application.log"
filePattern="${sys:catalina.base}/logs/application %d{yyyy-MM-dd}.log">
<PatternLayout>
<Pattern>%d{HH:mm:ss.SSS} [%t] %-5level %c{36} %l: %msg%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
<DefaultRolloverStrategy/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="my.package" level="info" additivity="false">
<AppenderRef ref="ApplicationLog"/>
</Logger>
<Logger name="my.test.package" level="debug" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
目前,这会写入名为application.log的日志,然后在午夜将当前的application.log文件复制到应用程序yyyy-MM-dd.log(文件名中的日期被正确替换),并继续记录第二天在application.log。
我希望在开始新的一天之前清除application.log。目前,这还没有发生,因此我的日志大小不断增加。我的第1天日志包含从第1天开始的所有日志记录,但是我的第2天日志包含从第1天和第2天开始的日志记录,依此类推。
如果发生翻转,如何重置application.log文件?根据{{3}},应该创建一个新的application.log文件,而不是当前正在继续的文件,但这不是我遇到的行为。
非常感谢任何帮助。
谢谢, 亚当
编辑:以下是rajuGT请求的配置跟踪。我在这里看不到任何问题......
2015-09-23 08:06:29,931 DEBUG Starting configuration XmlConfiguration[location=C:\apache-tomcat-8.0.23\webapps\myApp\WEB-INF\classes\log4j2.xml]
2015-09-23 08:06:29,931 DEBUG PluginManager 'Core' found 69 plugins
2015-09-23 08:06:29,932 DEBUG PluginManager 'Level' found 0 plugins
2015-09-23 08:06:29,934 DEBUG PluginManager 'Lookup' found 10 plugins
2015-09-23 08:06:29,939 DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout]. Searching for builder factory method...
2015-09-23 08:06:29,944 DEBUG Found builder factory method [newBuilder]: public static org.apache.logging.log4j.core.layout.PatternLayout$Builder org.apache.logging.log4j.core.layout.PatternLayout.newBuilder().
2015-09-23 08:06:29,962 DEBUG TypeConverterRegistry initializing.
2015-09-23 08:06:29,963 DEBUG PluginManager 'TypeConverter' found 21 plugins
2015-09-23 08:06:29,979 DEBUG Calling build() on class class org.apache.logging.log4j.core.layout.PatternLayout$Builder for element PatternLayout with params(name="%d{HH:mm:ss.SSS} [%t] %-5level %c{36} - %msg%n", Configuration(C:\apache-tomcat-8.0.23\webapps\myApp\WEB-INF\classes\log4j2.xml), null, name="null", name="null", name="null", name="null", name="null")
2015-09-23 08:06:29,980 DEBUG PluginManager 'Converter' found 33 plugins
2015-09-23 08:06:29,981 DEBUG Built Plugin[name=layout] OK from builder factory method.
2015-09-23 08:06:29,981 DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender]. Searching for builder factory method...
2015-09-23 08:06:29,984 INFO Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
2015-09-23 08:06:29,985 DEBUG PluginManager 'Converter' found 33 plugins
2015-09-23 08:06:29,987 DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream
2015-09-23 08:06:29,987 DEBUG Found builder factory method [newBuilder]: public static org.apache.logging.log4j.core.appender.ConsoleAppender$Builder org.apache.logging.log4j.core.appender.ConsoleAppender.newBuilder().
2015-09-23 08:06:29,994 DEBUG No PluginVisitorStrategy found on annotation [interface org.apache.logging.log4j.core.config.plugins.validation.constraints.Required]. Ignoring.
2015-09-23 08:06:29,994 DEBUG Encountered type [org.apache.logging.log4j.core.layout.PatternLayout] which can only be checked for null.
2015-09-23 08:06:29,998 DEBUG No PluginVisitorStrategy found on annotation [interface org.apache.logging.log4j.core.config.plugins.validation.constraints.Required]. Ignoring.
2015-09-23 08:06:29,998 DEBUG Encountered type [org.apache.logging.log4j.core.appender.ConsoleAppender$Target] which can only be checked for null.
2015-09-23 08:06:29,999 DEBUG No PluginVisitorStrategy found on annotation [interface org.apache.logging.log4j.core.config.plugins.validation.constraints.Required]. Ignoring.
2015-09-23 08:06:29,999 DEBUG Calling build() on class class org.apache.logging.log4j.core.appender.ConsoleAppender$Builder for element Console with params(PatternLayout(%d{HH:mm:ss.SSS} [%t] %-5level %c{36} - %msg%n), null, name="SYSTEM_OUT", name="Console", name="null", name="null")
2015-09-23 08:06:30,000 DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream
2015-09-23 08:06:30,001 DEBUG Built Plugin[name=appender] OK from builder factory method.
2015-09-23 08:06:30,001 DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout]. Searching for builder factory method...
2015-09-23 08:06:30,002 DEBUG Found builder factory method [newBuilder]: public static org.apache.logging.log4j.core.layout.PatternLayout$Builder org.apache.logging.log4j.core.layout.PatternLayout.newBuilder().
2015-09-23 08:06:30,003 DEBUG Calling build() on class class org.apache.logging.log4j.core.layout.PatternLayout$Builder for element PatternLayout with params(name="%d{HH:mm:ss.SSS} [%t] %-5level %c{36} %l: %msg%n", Configuration(C:\apache-tomcat-8.0.23\webapps\myApp\WEB-INF\classes\log4j2.xml), null, name="null", name="null", name="null", name="null", name="null")
2015-09-23 08:06:30,004 DEBUG Built Plugin[name=layout] OK from builder factory method.
2015-09-23 08:06:30,004 DEBUG Building Plugin[name=TimeBasedTriggeringPolicy, class=org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy]. Searching for builder factory method...
2015-09-23 08:06:30,009 DEBUG No builder factory method found in class org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy. Going to try finding a factory method instead.
2015-09-23 08:06:30,009 DEBUG Still building Plugin[name=TimeBasedTriggeringPolicy, class=org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy]. Searching for factory method...
2015-09-23 08:06:30,010 DEBUG Found factory method [createPolicy]: public static org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy.createPolicy(java.lang.String,java.lang.String).
2015-09-23 08:06:30,016 DEBUG Calling createPolicy on class org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy for element TimeBasedTriggeringPolicy with params(name="1", name="true")
2015-09-23 08:06:30,018 DEBUG Built Plugin[name=TimeBasedTriggeringPolicy] OK from factory method.
2015-09-23 08:06:30,018 DEBUG Building Plugin[name=Policies, class=org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy]. Searching for builder factory method...
2015-09-23 08:06:30,019 DEBUG No builder factory method found in class org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy. Going to try finding a factory method instead.
2015-09-23 08:06:30,019 DEBUG Still building Plugin[name=Policies, class=org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy]. Searching for factory method...
2015-09-23 08:06:30,019 DEBUG Found factory method [createPolicy]: public static org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy.createPolicy(org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy[]).
2015-09-23 08:06:30,020 DEBUG Calling createPolicy on class org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy for element Policies with params(={TimeBasedTriggeringPolicy})
2015-09-23 08:06:30,020 DEBUG Built Plugin[name=Policies] OK from factory method.
2015-09-23 08:06:30,021 DEBUG Building Plugin[name=DefaultRolloverStrategy, class=org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy]. Searching for builder factory method...
2015-09-23 08:06:30,023 DEBUG No builder factory method found in class org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy. Going to try finding a factory method instead.
2015-09-23 08:06:30,023 DEBUG Still building Plugin[name=DefaultRolloverStrategy, class=org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy]. Searching for factory method...
2015-09-23 08:06:30,024 DEBUG Found factory method [createStrategy]: public static org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy.createStrategy(java.lang.String,java.lang.String,java.lang.String,java.lang.String,org.apache.logging.log4j.core.config.Configuration).
2015-09-23 08:06:30,024 DEBUG Calling createStrategy on class org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy for element DefaultRolloverStrategy with params(name="null", name="null", name="null", name="null", Configuration(C:\apache-tomcat-8.0.23\webapps\myApp\WEB-INF\classes\log4j2.xml))
2015-09-23 08:06:30,025 DEBUG Built Plugin[name=DefaultRolloverStrategy] OK from factory method.
2015-09-23 08:06:30,025 DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.RollingFileAppender]. Searching for builder factory method...
2015-09-23 08:06:30,026 DEBUG No builder factory method found in class org.apache.logging.log4j.core.appender.RollingFileAppender. Going to try finding a factory method instead.
2015-09-23 08:06:30,026 DEBUG Still building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.RollingFileAppender]. Searching for factory method...
2015-09-23 08:06:30,026 DEBUG Found factory method [createAppender]: public static org.apache.logging.log4j.core.appender.RollingFileAppender org.apache.logging.log4j.core.appender.RollingFileAppender.createAppender(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy,org.apache.logging.log4j.core.appender.rolling.RolloverStrategy,org.apache.logging.log4j.core.Layout,org.apache.logging.log4j.core.Filter,java.lang.String,java.lang.String,java.lang.String,org.apache.logging.log4j.core.config.Configuration).
2015-09-23 08:06:30,029 DEBUG Calling createAppender on class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile with params(name="C:\apache-tomcat-8.0.23/logs/application.log", name="C:\apache-tomcat-8.0.23/logs/application %d{yyyy-MM-dd}.log", name="null", name="ApplicationLog", name="null", name="null", name="null", Policies(CompositeTriggeringPolicy{TimeBasedTriggeringPolicy}), DefaultRolloverStrategy(DefaultRolloverStrategy(min=1, max=7)), PatternLayout(%d{HH:mm:ss.SSS} [%t] %-5level %c{36} %l: %msg%n), null, name="null", name="null", name="null", Configuration(C:\apache-tomcat-8.0.23\webapps\myApp\WEB-INF\classes\log4j2.xml))
2015-09-23 08:06:30,041 DEBUG Starting RollingFileManager C:\apache-tomcat-8.0.23/logs/application.log
2015-09-23 08:06:30,044 DEBUG PluginManager 'FileConverter' found 2 plugins
2015-09-23 08:06:30,049 TRACE PatternProcessor.getNextTime returning 2015/09/24-00:00:00.000, nextFileTime=2015/09/23-00:00:00.000, prevFileTime=1970/01/01-10:00:00.000, current=2015/09/23-08:06:30.048, freq=DAILY
2015-09-23 08:06:30,049 TRACE PatternProcessor.getNextTime returning 2015/09/24-00:00:00.000, nextFileTime=2015/09/23-00:00:00.000, prevFileTime=2015/09/23-00:00:00.000, current=2015/09/23-08:06:30.049, freq=DAILY
2015-09-23 08:06:30,050 DEBUG Built Plugin[name=appender] OK from factory method.
2015-09-23 08:06:30,050 DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin]. Searching for builder factory method...
2015-09-23 08:06:30,051 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.AppendersPlugin. Going to try finding a factory method instead.
2015-09-23 08:06:30,051 DEBUG Still building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin]. Searching for factory method...
2015-09-23 08:06:30,051 DEBUG Found factory method [createAppenders]: public static java.util.concurrent.ConcurrentMap org.apache.logging.log4j.core.config.AppendersPlugin.createAppenders(org.apache.logging.log4j.core.Appender[]).
2015-09-23 08:06:30,052 DEBUG Calling createAppenders on class org.apache.logging.log4j.core.config.AppendersPlugin for element Appenders with params(={Console, ApplicationLog})
2015-09-23 08:06:30,052 DEBUG Built Plugin[name=appenders] OK from factory method.
2015-09-23 08:06:30,052 DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. Searching for builder factory method...
2015-09-23 08:06:30,053 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.AppenderRef. Going to try finding a factory method instead.
2015-09-23 08:06:30,053 DEBUG Still building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. Searching for factory method...
2015-09-23 08:06:30,053 DEBUG Found factory method [createAppenderRef]: public static org.apache.logging.log4j.core.config.AppenderRef org.apache.logging.log4j.core.config.AppenderRef.createAppenderRef(java.lang.String,org.apache.logging.log4j.Level,org.apache.logging.log4j.core.Filter).
2015-09-23 08:06:30,054 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element AppenderRef with params(name="ApplicationLog", name="null", null)
2015-09-23 08:06:30,054 DEBUG Built Plugin[name=AppenderRef] OK from factory method.
2015-09-23 08:06:30,055 DEBUG Building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig]. Searching for builder factory method...
2015-09-23 08:06:30,055 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.LoggerConfig. Going to try finding a factory method instead.
2015-09-23 08:06:30,056 DEBUG Still building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig]. Searching for factory method...
2015-09-23 08:06:30,056 DEBUG Found factory method [createLogger]: public static org.apache.logging.log4j.core.config.LoggerConfig org.apache.logging.log4j.core.config.LoggerConfig.createLogger(java.lang.String,org.apache.logging.log4j.Level,java.lang.String,java.lang.String,org.apache.logging.log4j.core.config.AppenderRef[],org.apache.logging.log4j.core.config.Property[],org.apache.logging.log4j.core.config.Configuration,org.apache.logging.log4j.core.Filter).
2015-09-23 08:06:30,057 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig for element Logger with params(name="false", name="INFO", name="my.package", name="null", ={ApplicationLog}, ={}, Configuration(C:\apache-tomcat-8.0.23\webapps\myApp\WEB-INF\classes\log4j2.xml), null)
2015-09-23 08:06:30,059 DEBUG Built Plugin[name=logger] OK from factory method.
2015-09-23 08:06:30,059 DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. Searching for builder factory method...
2015-09-23 08:06:30,059 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.AppenderRef. Going to try finding a factory method instead.
2015-09-23 08:06:30,060 DEBUG Still building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. Searching for factory method...
2015-09-23 08:06:30,060 DEBUG Found factory method [createAppenderRef]: public static org.apache.logging.log4j.core.config.AppenderRef org.apache.logging.log4j.core.config.AppenderRef.createAppenderRef(java.lang.String,org.apache.logging.log4j.Level,org.apache.logging.log4j.core.Filter).
2015-09-23 08:06:30,061 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element AppenderRef with params(name="Console", name="null", null)
2015-09-23 08:06:30,061 DEBUG Built Plugin[name=AppenderRef] OK from factory method.
2015-09-23 08:06:30,061 DEBUG Building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig]. Searching for builder factory method...
2015-09-23 08:06:30,061 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.LoggerConfig. Going to try finding a factory method instead.
2015-09-23 08:06:30,062 DEBUG Still building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig]. Searching for factory method...
2015-09-23 08:06:30,062 DEBUG Found factory method [createLogger]: public static org.apache.logging.log4j.core.config.LoggerConfig org.apache.logging.log4j.core.config.LoggerConfig.createLogger(java.lang.String,org.apache.logging.log4j.Level,java.lang.String,java.lang.String,org.apache.logging.log4j.core.config.AppenderRef[],org.apache.logging.log4j.core.config.Property[],org.apache.logging.log4j.core.config.Configuration,org.apache.logging.log4j.core.Filter).
2015-09-23 08:06:30,064 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig for element Logger with params(name="false", name="DEBUG", name="my.test.package", name="null", ={Console}, ={}, Configuration(C:\apache-tomcat-8.0.23\webapps\myApp\WEB-INF\classes\log4j2.xml), null)
2015-09-23 08:06:30,064 DEBUG Built Plugin[name=logger] OK from factory method.
2015-09-23 08:06:30,065 DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. Searching for builder factory method...
2015-09-23 08:06:30,065 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.AppenderRef. Going to try finding a factory method instead.
2015-09-23 08:06:30,065 DEBUG Still building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. Searching for factory method...
2015-09-23 08:06:30,066 DEBUG Found factory method [createAppenderRef]: public static org.apache.logging.log4j.core.config.AppenderRef org.apache.logging.log4j.core.config.AppenderRef.createAppenderRef(java.lang.String,org.apache.logging.log4j.Level,org.apache.logging.log4j.core.Filter).
2015-09-23 08:06:30,066 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element AppenderRef with params(name="Console", name="null", null)
2015-09-23 08:06:30,066 DEBUG Built Plugin[name=AppenderRef] OK from factory method.
2015-09-23 08:06:30,067 DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. Searching for builder factory method...
2015-09-23 08:06:30,067 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger. Going to try finding a factory method instead.
2015-09-23 08:06:30,067 DEBUG Still building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. Searching for factory method...
2015-09-23 08:06:30,068 DEBUG Found factory method [createLogger]: public static org.apache.logging.log4j.core.config.LoggerConfig org.apache.logging.log4j.core.config.LoggerConfig$RootLogger.createLogger(java.lang.String,org.apache.logging.log4j.Level,java.lang.String,org.apache.logging.log4j.core.config.AppenderRef[],org.apache.logging.log4j.core.config.Property[],org.apache.logging.log4j.core.config.Configuration,org.apache.logging.log4j.core.Filter).
2015-09-23 08:06:30,068 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger for element Root with params(name="null", name="ERROR", name="null", ={Console}, ={}, Configuration(C:\apache-tomcat-8.0.23\webapps\myApp\WEB-INF\classes\log4j2.xml), null)
2015-09-23 08:06:30,069 DEBUG Built Plugin[name=root] OK from factory method.
2015-09-23 08:06:30,069 DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin]. Searching for builder factory method...
2015-09-23 08:06:30,071 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.LoggersPlugin. Going to try finding a factory method instead.
2015-09-23 08:06:30,071 DEBUG Still building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin]. Searching for factory method...
2015-09-23 08:06:30,071 DEBUG Found factory method [createLoggers]: public static org.apache.logging.log4j.core.config.Loggers org.apache.logging.log4j.core.config.LoggersPlugin.createLoggers(org.apache.logging.log4j.core.config.LoggerConfig[]).
2015-09-23 08:06:30,072 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.LoggersPlugin for element Loggers with params(={my.package, my.test.package, root})
2015-09-23 08:06:30,072 DEBUG Built Plugin[name=loggers] OK from factory method.
2015-09-23 08:06:30,074 DEBUG Started configuration XmlConfiguration[location=C:\apache-tomcat-8.0.23\webapps\myApp\WEB-INF\classes\log4j2.xml] OK.
2015-09-23 08:06:30,075 TRACE Stopping org.apache.logging.log4j.core.config.DefaultConfiguration@43db0439...
2015-09-23 08:06:30,075 TRACE AbstractConfiguration stopped 0 AsyncLoggerConfigs.
2015-09-23 08:06:30,075 TRACE AbstractConfiguration stopped 0 AsyncAppenders.
2015-09-23 08:06:30,075 TRACE AbstractConfiguration stopped 1 Appenders.
2015-09-23 08:06:30,076 TRACE AbstractConfiguration stopped 0 Loggers.
2015-09-23 08:06:30,076 DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@43db0439 OK
2015-09-23 08:06:30,083 DEBUG Registering MBean org.apache.logging.log4j2:type=672866478
2015-09-23 08:06:30,087 DEBUG Registering MBean org.apache.logging.log4j2:type=672866478,component=StatusLogger
2015-09-23 08:06:30,089 DEBUG Registering MBean org.apache.logging.log4j2:type=672866478,component=ContextSelector
2015-09-23 08:06:30,092 DEBUG Registering MBean org.apache.logging.log4j2:type=672866478,component=Loggers,name=
2015-09-23 08:06:30,093 DEBUG Registering MBean org.apache.logging.log4j2:type=672866478,component=Loggers,name=my.package
2015-09-23 08:06:30,093 DEBUG Registering MBean org.apache.logging.log4j2:type=672866478,component=Loggers,name=my.test.package
2015-09-23 08:06:30,095 DEBUG Registering MBean org.apache.logging.log4j2:type=672866478,component=Appenders,name=Console
2015-09-23 08:06:30,096 DEBUG Registering MBean org.apache.logging.log4j2:type=672866478,component=Appenders,name=ApplicationLog
2015-09-23 08:06:30,096 DEBUG Reconfiguration complete for context[name=672866478] at null (org.apache.logging.log4j.core.LoggerContext@655b289) with optional ClassLoader: null
2015-09-23 08:06:30,097 DEBUG Shutdown hook enabled. Registering a new one.
2015-09-23 08:06:30,100 DEBUG LoggerContext[name=672866478, org.apache.logging.log4j.core.LoggerContext@655b289] started OK.
答案 0 :(得分:2)
我通过调试源代码来解决这个问题,因为我的日志应该滚动。
显然,有一个未记录的属性可以放在名为&#34;追加&#34;的RollingFile元素中,当设置为 false 时,将写入当前日志文件开始。不幸的是,此属性的默认值为 true ,这会导致附加当前日志文件而不是重新启动。
所以我的最终log4j2.xml看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %c{36} - %msg%n"/>
</Console>
<RollingFile
name="ApplicationLog"
fileName="${sys:catalina.base}/logs/application.log"
filePattern="${sys:catalina.base}/logs/application %d{yyyy-MM-dd}.log"
append="false">
<PatternLayout>
<Pattern>%d{HH:mm:ss.SSS} [%t] %-5level %c{36} %l: %msg%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
<DefaultRolloverStrategy/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="my.package" level="info" additivity="false">
<AppenderRef ref="ApplicationLog"/>
</Logger>
<Logger name="my.test.package" level="debug" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
希望这可以帮助其他人在不到3天的时间内解决这个问题。
编辑:事实证明此属性已记录here(表格中的第一个参数),但对我来说仍然没有意义为什么追加是默认行为。为什么我希望我的文件大小永远增加!?无论如何,不是重点,只是咆哮!
谢谢, 亚当
答案 1 :(得分:0)