我第一次尝试使用log4j2。它是根据我的配置进行记录,除了它还向控制台输出类似配置调试消息的内容:
2013-08-07 19:36:50,870 DEBUG Generated plugins in 0.000029274 seconds
2013-08-07 19:36:50,871 DEBUG Generated plugins in 0.000028703 seconds
2013-08-07 19:36:50,871 DEBUG Generated plugins in 0.000022613 seconds
2013-08-07 19:36:50,872 DEBUG Generated plugins in 0.000017492 seconds
2013-08-07 19:36:50,872 DEBUG Generated plugins in 0.000017009 seconds
2013-08-07 19:36:50,873 DEBUG Generated plugins in 0.000025645 seconds
2013-08-07 19:36:50,873 DEBUG Generated plugins in 0.000017140 seconds
2013-08-07 19:36:50,873 DEBUG Generated plugins in 0.000017438 seconds
2013-08-07 19:36:50,874 DEBUG Generated plugins in 0.000018848 seconds
2013-08-07 19:36:50,874 DEBUG Generated plugins in 0.000018203 seconds
2013-08-07 19:36:50,875 DEBUG Generated plugins in 0.000017775 seconds
2013-08-07 19:36:50,875 DEBUG Generated plugins in 0.000018104 seconds
2013-08-07 19:36:50,876 DEBUG Generated plugins in 0.000017015 seconds
2013-08-07 19:36:50,876 DEBUG Generated plugins in 0.000018079 seconds
2013-08-07 19:36:50,890 DEBUG Calling createLayout on class org.apache.logging.log4j.core.layout.PatternLayout for element PatternLayout with params(pattern="%d{HH:mm:ss.SSS} %-5level %msg%n", Configuration(.../conf/preprocessor.log4j2.xml), null, charset="null", suppressExceptions="null")
2013-08-07 19:36:50,890 DEBUG Generated plugins in 0.000032718 seconds
2013-08-07 19:36:50,893 DEBUG Calling createAppender on class org.apache.logging.log4j.core.appender.ConsoleAppender for element Console with params(PatternLayout(%d{HH:mm:ss.SSS} %-5level %msg%n), null, target="SYSTEM_OUT", name="Console", follow="null", suppressExceptions="null")
2013-08-07 19:36:50,894 DEBUG Calling createLayout on class org.apache.logging.log4j.core.layout.PatternLayout for element PatternLayout with params(pattern="%d{MM-dd HH:mm:ss.SSS} %-5level %msg%n", Configuration(.../conf/preprocessor.log4j2.xml), null, charset="null", suppressExceptions="null")
2013-08-07 19:36:50,895 DEBUG Calling createPolicy on class org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy for element SizeBasedTriggeringPolicy with params(size="10 MB")
2013-08-07 19:36:50,897 DEBUG Calling createPolicy on class org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy for element Policies with params(policies={SizeBasedTriggeringPolicy(size=10485760)})
2013-08-07 19:36:50,900 DEBUG Calling createAppender on class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile with params(fileName="logs/preprocessor.log", filePattern="logs/preprocessor-%d{yyyy-MM-dd-HH}-%i.log.gz", append="null", name="RollingFileAll", bufferedIO="null", immediateFlush="null", Policies(CompositeTriggeringPolicy{SizeBasedTriggeringPolicy(size=10485760)}), null, PatternLayout(%d{MM-dd HH:mm:ss.SSS} %-5level %msg%n), null, suppressExceptions="null", advertise="null", advertiseURI="null", Configuration(..../conf/preprocessor.log4j2.xml))
2013-08-07 19:36:50,902 DEBUG Starting RollingFileManager logs/preprocessor.log
2013-08-07 19:36:50,904 DEBUG Generated plugins in 0.000022500 seconds
2013-08-07 19:36:50,906 DEBUG Calling createAppenders on class org.apache.logging.log4j.core.config.plugins.AppendersPlugin for element appenders with params(appenders={Console, RollingFileAll})
2013-08-07 19:36:50,906 DEBUG Generated plugins in 0.000019671 seconds
2013-08-07 19:36:50,908 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element appender-ref with params(ref="Console", level="WARN", null)
2013-08-07 19:36:50,908 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element appender-ref with params(ref="RollingFileAll", level="null", null)
2013-08-07 19:36:50,910 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig for element logger with params(additivity="false", level="ERROR", name="eventLogger", includeLocation="null", appender-ref={org.apache.logging.log4j.core.config.AppenderRef@22b27cca, org.apache.logging.log4j.core.config.AppenderRef@741ec391}, properties={}, Configuration(.../conf/preprocessor.log4j2.xml), null)
2013-08-07 19:36:50,912 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element appender-ref with params(ref="Console", level="INFO", null)
2013-08-07 19:36:50,913 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element appender-ref with params(ref="RollingFileAll", level="null", null)
2013-08-07 19:36:50,915 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger for element root with params(additivity="null", level="DEBUG", includeLocation="null", appender-ref={org.apache.logging.log4j.core.config.AppenderRef@72607cad, org.apache.logging.log4j.core.config.AppenderRef@1c997c85}, properties={}, Configuration(.../preprocessor.log4j2.xml), null)
2013-08-07 19:36:50,916 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.plugins.LoggersPlugin for element loggers with params(loggers={eventLogger, root})
我的配置文件preprocessor.log4j2.xml如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<configuration status="DEBUG">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %msg%n" />
</Console>
<RollingFile name="RollingFileAll" fileName="logs/preprocessor.log"
filePattern="logs/preprocessor-%d{yyyy-MM-dd-HH}-%i.log.gz">
<PatternLayout pattern="%d{MM-dd HH:mm:ss.SSS} %-5level %msg%n" />
<Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
</RollingFile>
</appenders>
<loggers>
<root level="DEBUG">
<appender-ref ref="Console" level="INFO" />
<appender-ref ref="RollingFileAll" />
</root>
</loggers>
</configuration>
这就是我在java中配置(我知道autoconfigure)log4j2的方式:
File file = new File(LOG4J2_CONF_FILE);
Configurator.initialize("preprocessor", null, file.toURI());
我尝试添加EventLogger记录器并禁用其输出,但它没有帮助。您是否知道如何避免出现此配置调试消息?
提前感谢您的任何提示。
答案 0 :(得分:9)
只需从配置标记
中删除status="DEBUG"
即可