Dino Tw
Dino Tw

Reputation: 3321

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/. When the level is configured to TRACE, all levels of the loggings print, and the level ALL has the same effect. org.apache.log4j.Logger has the method trace(Object message), but all(Object message).

So my question is when is the time to use TRACE vs ALL?

Upvotes: 2

Views: 2831

Answers (2)

Michiel Bugher
Michiel Bugher

Reputation: 1065

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?

The answer is custom log levels: 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.

Let's say you defined a custom level set to 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.

Since ALL is represented by Integer.MAX_VALUE, nothing can be defined above that, even custom levels. So, it will always log ALL messages in all cases.

Upvotes: 2

Paul Vargas
Paul Vargas

Reputation: 42030

OFF can be used to turn off logging and ALL can be used to enable logging of all messages. e.g.:

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

They are used as shortcuts. log4j uses internally to limit the level (threshold).

Upvotes: 1

Related Questions