2

In log4j.xml one can specifiy a certain log level that is applied:

<logger name="com.foo.bar.FooBar"
    additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="myCustomAppender" />
</logger>

Does a log level include other log levels? I'd like so see both debug and error messages. Does the log level DEBUG include ERROR? Or vice versa?

Or does DEBUG only include TRACE and DEBUG, such that:

OFF > TRACE > DEBUG > INFO > WARN > ERROR > ALL

user1438038
  • 5,821
  • 6
  • 60
  • 94
  • You give the Minimum loglevel in your configuration. That means if you set the Level to debug, debug, info, warn and error will be printet. But if you set the loglevel to error, only error Messages will be shown – Jens Sep 29 '16 at 13:56

1 Answers1

1

Yes, as you've mentioned in your post all the log levels to the right are included. Unless of course its turned off, no messages will be logged.

Not vice versa though, if you log4j.xml set level value to ERROR, nothing on its left will be logged, only to the right. Ex. Log level of ERROR doesn't include WARN/INFO/DEBUG...., similarly log level of DEBUG will not have TRACE messages.

Shyam
  • 76
  • 8
  • 2
    But if all levels to the right are included, I'd have to switch ``ALL`` and ``OFF``, right? It should be ``ALL > TRACE > DEBUG > INFO > WARN > ERROR or OFF`` then. – user1438038 Sep 29 '16 at 14:18
  • 1
    Correct, thank you for catching it. And it should be [ALL](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html#ALL) < [TRACE](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html#TRACE) < [DEBUG](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html#DEBUG) < [INFO](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html#INFO) < [WARN](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html#WARN) < [ERROR](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html#ERROR) < OFF – Shyam Sep 29 '16 at 14:44
  • Is this behaviour documented somewhere? I read the linked docs yesterday and couldn't find this statement. – Hubert Grzeskowiak Sep 30 '16 at 08:05
  • 1
    http://stackoverflow.com/questions/7745885/log4j-logging-hierarchy-order This has details of the log level precedence. – Shyam Sep 30 '16 at 14:22