Reputation: 537
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?
Upvotes: 1
Views: 959
Reputation: 47865
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:
com.foo.bar
will be subject to the INFO
levelcom.foo.bas
will be subject to the WARN
levelLogback'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.
Upvotes: 1