1
votes

I have some doubts regarding levels of log messages. I know there are different type of logging level and when to use what. But the thing that i don't understand is who decides which levels of log message to be printed in destination in Logback?

Is it Logger itself or appenders ?

By logger itself i mean if i set the logger logging level to warning then logger won't pass levels less then warning (info,trace,debug) messages to appenders or is it the responsibility of appenders to drop message with level less then warning to destination?

1

1 Answers

1
votes

You set a level on a Logger not on an Appender. Here are some examples from Logback's XML configuration:

<logger name="com.foo.bar" level="INFO"/>
<logger name="com.foo.bas" level="WARN"/>

In these examples:

  • Any Loggers belonging to the namespace: com.foo.bar will be subject to the INFO level
  • Any Loggers belonging to the namespace: com.foo.bas will be subject to the WARN level

Logback's rootLogger defines the default level, the following configuration tells Logback to apply the INFO level to all loggers except for those loggers which are explicitly configured using a <logger/> declaration:

<root level="INFO">          
  <appender-ref ref="STDOUT" />
</root>  

More details in the docs.

To answer this specific question:

By logger itself i mean if i set the logger logging level to warning then logger won't pass levels less then warning (info,trace,debug) messages to appenders or is it the responsibility of appenders to drop message with level less then warning to destination?

If your Logger is created for a class in the namepsace: com.x.y and you have defined a <logger name="com.x.y" level="INFO"/> then the Logger will filter out any logger.debug() invocations since the DEBUG level is lower than the INFO level.