简体   繁体   English

log4j 级别配置 TRACE 和 ALL

[英]log4j level configuration TRACE and ALL

My understanding for the org.apache.log4j level is like the "Log4j Logger Output" table in this page, http://javapapers.com/log4j/log4j-levels/ .我对org.apache.log4j级别的理解就像本页http://javapapers.com/log4j/log4j-levels/ 中的“Log4j Logger Output”表。 When the level is configured to TRACE, all levels of the loggings print, and the level ALL has the same effect.当级别配置为 TRACE 时,所有级别的日志都会打印,并且级别 ALL 具有相同的效果。 org.apache.log4j.Logger has the method trace(Object message), but all(Object message). org.apache.log4j.Logger 有方法 trace(Object message),但是 all(Object message)。

So my question is when is the time to use TRACE vs ALL?所以我的问题是什么时候使用 TRACE 与 ALL?

OFF can be used to turn off logging and ALL can be used to enable logging of all messages. OFF可用于关闭日志记录, ALL可用于启用所有消息的日志记录。 eg: 例如:

<category name="org.apache.commons">
    <priority value="OFF" />
</category>

They are used as shortcuts. 它们用作快捷方式。 log4j uses internally to limit the level ( threshold ). log4j在内部使用以限制级别( threshold )。

I know that this question is old, but I feel like it could use a better answer.我知道这个问题很旧,但我觉得它可以使用更好的答案。 At least, as I understand it.至少,据我所知。

Why would you need an ALL level when TRACE is also the top?当 TRACE 也是顶级时,为什么您需要 ALL 级别?

The answer is custom log levels: https://logging.apache.org/log4j/2.x/manual/customloglevels.html答案是自定义日志级别: https : //logging.apache.org/log4j/2.x/manual/customloglevels.html

The idea is that you can define your own log levels within certain integer ranges and they will still be respected.这个想法是您可以在某些整数范围内定义自己的日志级别,并且它们仍然会受到尊重。

For instance, these are the default log levels:例如,这些是默认的日志级别:

Standard Level  intLevel
OFF             0
FATAL           100
ERROR           200
WARN            300
INFO            400
DEBUG           500
TRACE           600
ALL             Integer.MAX_VALUE

In this case, it seems like TRACE would log everything regardless, but that is not true because of custom levels.在这种情况下,似乎 TRACE 无论如何都会记录所有内容,但由于自定义级别,情况并非如此。

Let's say you defined a custom level set to 650:假设您定义了一个自定义级别设置为 650:

Standard Level  intLevel
Standard Level  intLevel
OFF             0
FATAL           100
ERROR           200
WARN            300
INFO            400
DEBUG           500
TRACE           600
MYLEVEL         650
ALL             Integer.MAX_VALUE

If your log level were set to TRACE, MYLEVEL would not be logged.如果您的日志级别设置为 TRACE,则不会记录 MYLEVEL。

Since ALL is represented by Integer.MAX_VALUE, nothing can be defined above that, even custom levels.由于 ALL 由 Integer.MAX_VALUE 表示,因此无法在其上定义任何内容,甚至自定义级别。 So, it will always log ALL messages in all cases.因此,它会在所有情况下始终记录所有消息。

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

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