Java 跟踪日志级别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19678324/
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-12 19:20:06  来源:igfitidea点击:

TRACE log level

javalog4j

提问by vico

I know following log levels in Log4J:

我知道 Log4J 中的以下日志级别:

ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF

But in some samplers I found TRACE

但是在一些采样器中我发现了 TRACE

and trace()metod:

trace()方法:

Logger LOG = Logger.getLogger(MyClass.class);
LOG.trace("Instance created of AnotherClass");

In my IDE method trace()is not recognizable. Is this old Log4J library and TRACEappears only in some new one?

在我的 IDE 方法trace()中无法识别。这个旧的 Log4J 库是不是TRACE只出现在一些新的库中?

采纳答案by Paul Vargas

The org.apache.log4j.Level.TRACElevel was added to log4j in the version 1.2.12

org.apache.log4j.Level.TRACE级别加入的log4j的版本1.2.12

You need to updatethe version of your log4j's library.

您需要更新log4j 库的版本。

回答by Vrushank

Log4j itself does not have the TRACElevel. That log level is provided by the newer logging facades like commons-loggingor slf4j. These facades itself do not log but delegate to underlying logging providers like log4jor logback.

Log4j 本身没有这个TRACE级别。该日志级别由较新的日志记录外观提供,例如commons-loggingslf4j。这些外观本身不记录,而是委托给底层的日志记录提供者,如log4jlogback

回答by Menuka Ishan

you have to mention it on your log4j2-test.xml

你必须在你的log4j2-test.xml 中提到它

<Loggers>
<Logger name="com.foo.Bar" level="trace">
  <AppenderRef ref="Console"/>
</Logger>
<Root level="error">
  <AppenderRef ref="Console"/>
</Root>

You have to give your logger level as trace if you want to log the traces

如果要记录跟踪,则必须将记录器级别作为跟踪

Refer this
https://logging.apache.org/log4j/2.x/manual/configuration.html#Additivity

请参阅此
https://logging.apache.org/log4j/2.x/manual/configuration.html#Additivity