简体   繁体   中英

Log4j2 logs at TRACE level before tests, including parsing the xml config. How to change level before logging begins?

I just set up a project to test with junit jupiter (junit 5) and I'm getting a bunch of log4j2 output at the TRACE level, regardless of the level I'm setting in my xml config. Example output follows. How can I change the level at which log4j2 logs before the xml is even parsed?

Here's my xml config:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="TRACE" packages="com.travisfw">
  <Appenders>
    <Console name="console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
    </Console>
  </Appenders>
  <Loggers>
    <Root level="WARN">
      <AppenderRef ref="console" />
    </Root>
    <Logger level="WARN" name="com.travisfw" additivity="false">
      <AppenderRef ref="console" />
    </Logger>
  </Loggers>
</Configuration>

And then, despite that WARN is the only level I ever set, I get DEBUG and TRACE output in the junit report, starting with where it finds my xml config:

2018-10-04 16:04:48,532 Test worker DEBUG Apache Log4j Core 2.11.1 initializing configuration XmlConfiguration[location=/home/.../build/resources/main/log4j2.xml]
2018-10-04 16:04:48,539 Test worker DEBUG Installed 1 script engine
2018-10-04 16:04:48,920 Test worker DEBUG Oracle Nashorn version: 1.8.0_181, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
2018-10-04 16:04:48,924 Test worker DEBUG Took 0.004073 seconds to load 0 plugins from package com.travisfw
2018-10-04 16:04:48,925 Test worker DEBUG PluginManager 'Core' found 117 plugins
2018-10-04 16:04:48,925 Test worker DEBUG PluginManager 'Level' found 0 plugins
2018-10-04 16:04:48,928 Test worker DEBUG PluginManager 'Lookup' found 13 plugins
2018-10-04 16:04:48,930 Test worker DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
2018-10-04 16:04:48,936 Test worker TRACE TypeConverterRegistry initializing.
2018-10-04 16:04:48,937 Test worker DEBUG PluginManager 'TypeConverter' found 26 plugins
2018-10-04 16:04:48,944 Test worker DEBUG PatternLayout$Builder(pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", PatternSelector=null, Configuration(/home/.../build/resources/main/log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", disableAnsi="null", noConsoleNoAnsi="null", header="null", footer="null")
2018-10-04 16:04:48,945 Test worker DEBUG PluginManager 'Converter' found 44 plugins
2018-10-04 16:04:48,946 Test worker DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender].
2018-10-04 16:04:48,954 Test worker DEBUG ConsoleAppender$Builder(target="SYSTEM_OUT", follow="null", direct="null", bufferedIo="null", bufferSize="null", immediateFlush="null", ignoreExceptions="null", PatternLayout(%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n), name="console", Configuration(/home/.../build/resources/main/log4j2.xml), Filter=null)
2018-10-04 16:04:48,958 Test worker DEBUG Starting OutputStreamManager SYSTEM_OUT.false.false
2018-10-04 16:04:48,959 Test worker DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
2018-10-04 16:04:48,964 Test worker DEBUG createAppenders(={console})
2018-10-04 16:04:48,965 Test worker DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2018-10-04 16:04:48,970 Test worker DEBUG createAppenderRef(ref="console", level="null", Filter=null)
2018-10-04 16:04:48,970 Test worker DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].

I'll spare you the full log, but it continues for a little while.

I think your issue is that you set the level of the status logger to TRACE: status="TRACE" . Try changing this to a different level - perhaps WARN.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM