Java Log4j2 配置中的“状态”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21065854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:20:57  来源:igfitidea点击:

What does “status” mean in Log4j2 configuration?

javaloggingconfigurationlog4jlog4j2

提问by Yurii Bondarenko

I just have finished adjustment of log4j2.xml configuration file and spotted something I don't really understand. So what is <Configuration status="SOME_STATUS_HERE">?

我刚刚完成了log4j2.xml配置文件的调整,发现了一些我不太明白的东西。那么什么是<Configuration status="SOME_STATUS_HERE">

Almost in all examples here : http://logging.apache.org/log4j/2.x/manual/configuration.htmlfolks from Apache added status to configuration.

几乎在这里的所有示例中:http: //logging.apache.org/log4j/2.x/manual/configuration.html来自 Apache 的人将状态添加到配置中。

For example here is the first one:

例如这里是第一个:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN"> <!--status="WARN" - what is this???--> 

 <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="error">
   <AppenderRef ref="Console"/>
  </Root>
 </Loggers>

</Configuration>

采纳答案by Remko Popma

The status logger is used internally by log4j2 components. Setting status="debug"(or "trace") in the configuration will cause this internal logging to be output to the command line.

状态记录器由 log4j2 组件在内部使用。配置中的设置status="debug"(或“跟踪”)将导致此内部日志记录输出到命令行。

It will print debug information about which log4j2 plugin components are loaded (all configuration elements map to log4j2 plugins), and more details like for example what appenders and loggers were found, what parameters they have and how they are combined.

它将打印有关加载了哪些 log4j2 插件组件的调试信息(所有配置元素都映射到 log4j2 插件),以及更多详细信息,例如找到了哪些 appender 和 logger,它们具有哪些参数以及它们如何组合。

This is useful for troubleshooting configuration issues.

这对于排除配置问题很有用。

From Log4j 2.9, you can use system property log4j2.debug(no value required) to turn on internal Log4j2 status logging even before the configuration file is loaded. Prior to version 2.9, the same can be achieved with system property -Dorg.apache.logging.log4j.simplelog.StatusLogger.level=TRACE.

从 Log4j 2.9 开始,您log4j2.debug甚至可以在加载配置文件之前使用系统属性(不需要值)打开内部 Log4j2 状态日志记录。在 2.9 版本之前,同样可以通过 system property 实现-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=TRACE

回答by skrtxao

In case someone is wondering where the Log4j2 XML <Configuration>element attributes are mentioned in the Log4j2 documentation, I thought it could be useful to provide the link here. See also a snapshot of the attribute list below:

如果有人想知道 Log4j2 文档中哪里<Configuration>提到了 Log4j2 XML元素属性,我认为在此处提供链接可能会很有用。另请参阅以下属性列表的快照:

Configuration element attributes

配置元素属性

回答by JGlass

And in case anyone is looking for the correct levels for the status attribute they're: trace, debug, info, warn, errorand fatal.

而如果有人正在寻找正确的水平他们的状态属性:tracedebuginfowarnerrorfatal

Log4j2 Configuration

Log4j2 配置