我目前正在使用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文件复制到application yyy-MM-DD . log(文件名中的日期会被正确替换),并在第二天继续在application.log中记录日志。
我希望application.log在新的一天开始之前被清除。目前,这种情况还没有发生,因此我的日志大小一直在增加。我的第1天日志包含第1天的所有日志,但我的第2天日志包含第1天和第2天的日志,依此类推。
如何重置应用程序。一旦发生翻滚,是否记录文件?根据Log4j 2.x文档,这是一个新的应用程序。应该创建日志文件,而不是继续当前文件,但这不是我正在经历的行为。
任何帮助将不胜感激。
谢谢,亚当
编辑:下面是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.
我通过调试源代码来解决这个问题,因为我的日志应该会滚动。
显然,有一个未记录的属性可以放在名为“append”的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天的时间内解决这个问题。
编辑:所以事实证明这个属性记录在这里(表中的第一个参数),但它仍然没有意义,为什么追加是默认行为。为什么我希望我的文件大小永远增加!?反正不是重点,只是咆哮!
谢谢,亚当
我们在Apache Tomcat上使用log4j2.3。我们最近从log4j1.2升级到log4j2.0。除了一个问题,它工作得很好。我们使用RollingFile Appender每天滚动日志文件。正如预期的那样,文件会在午夜之后滚动,但是当前日志文件不会清除前一天的日志条目。我们最终得到了一个日志文件,它的大小不断增加,并且包含了所有前几天的条目。 这是我们的滚动文件Appender配置: 有
使用Log4j2.8,有没有一种方法可以让我的日志每天旋转,但使当前文件具有恒定的名称? 示例: 我尝试了以下配置,但没有成功: 此外,当我在某一天首次启动应用程序时,我会遇到以下例外情况:
我在打印日志的应用程序中使用log4j。到目前为止,我只有一个日志文件(例如X. log),并且它在固定大小后滚动,例如4 MB。现在,我正在尝试将一些特定的请求和响应记录到不同的日志文件Y. Log。 我的要求是在4 MB之后也滚动Y.log文件。我正在为X和Y日志使用滚动文件追加器。Y、 日志将在X.log可用的同一位置创建。 但现在似乎两个日志文件在4 MB后都没有滚动。它继续附加到相同的日
据我所知,log4j2中的RollingFileAppender不会在指定的时间(比方说-在一小时结束时)回滚,而是在超过时间阈值后到达的第一个日志事件时回滚。 有没有一种方法可以触发一个事件,一方面会导致文件滚动,另一方面不会附加到日志中(或者会附加一些无关紧要的东西,比如空字符串)?
我好像拿不到滚动日志文件。 我的logback.xml配置有以下内容: 有意思。SIFT中“unknown.log”文件中的条目在分钟的停止处停止。之后,不会向SIFT文件写入任何内容,但我一直在catalina.out中获取条目:
问题内容: 我使用以下命令读取了Docker容器日志输出 我通过调用来将大量数据记录到node.js应用程序的日志中。我需要清理日志,因为它太长了,并且该命令首先运行日志的现有行,然后结束。我该如何清洁使其再次变短?我想查看类似的命令: 但是它似乎不存在。 问题答案: 首先,如果只需要查看较少的输出,则可以让docker只向您显示更新的行: 或者,您可以限制一些行: 要删除Docker for L