简体   繁体   English

Log4j2在测试之前记录在TRACE级别,包括解析xml配置。 如何在开始记录之前更改级别?

[英]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. 我刚刚设置了一个项目来测试junit jupiter(junit 5),我在TRACE级别获得了一堆log4j2输出,无论我在xml配置中设置的级别如何。 Example output follows. 示例输出如下。 How can I change the level at which log4j2 logs before the xml is even parsed? 如何在解析xml之前更改log4j2的日志级别?

Here's my xml config: 这是我的xml配置:

<?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: 然后,尽管WARN是我设置的唯一级别,但我在junit报告中获得了DEBUG和TRACE输出,从找到我的xml配置的位置开始:

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" . 我认为您的问题是您将状态记录器的级别设置为TRACE: status="TRACE" Try changing this to a different level - perhaps WARN. 尝试将其更改为不同的级别 - 也许是WARN。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 程序执行期间如何更改log4j2中的日志记录级别 - How to change the logging level in log4j2 during program execution 我想在运行时将Log4j2实现的日志级别从“ Logs and trace”选项更改为Websphere日志级别 - I'cant change the log level for log4j2 implementation to websphere log level at runtime from “Logs and trace” option Log4j2 不会在运行时更改日志记录级别 - Log4j2 does not change logging level at runtime 以编程方式更改 Log4j2 中的日志级别 - Programmatically change log level in Log4j2 如何以编程方式更改log4j2中的日志级别 - How to change programatically log level in log4j2 如何在登录文件之前使用Log4j2 xml重写追加程序修改LogEvent - How to use Log4j2 xml Rewrite appender for modifying LogEvent before it logs in file 如何以编程方式更改log4j2中的AppenderRef级别? - How can I change the AppenderRef Level in log4j2 programmatically? 未记录 TRACE 级别的消息。 log4j 如何启用跟踪日志记录级别 - TRACE level messages not being logged. log4j How to enable trace logging level Log4j2 - 除Spring之外的调试级日志记录 - Log4j2 - debug-level logging except for Spring 在哪里将系统属性“org.apache.logging.log4j.simplelog.StatusLogger.level”设置为 TRACE 以显示 Log4j2 内部初始化日志记录 - Where to Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level' to TRACE to show Log4j2 internal initialization logging
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM