Logback level element vs. level attribute

639 views Asked by At

The question is simple. In some logback.xmls I see level as an element:

<logger name="mylog" additivity="false">
  <level value="DEBUG" />
  <appender-ref ref="fileAppender" />
</logger>

But in some it is written as an attribute:

<logger name="mylog" additivity="false" level="debug">
  <appender-ref ref="fileAppender" />
</logger>

What is the difference?

Thanks.

1

There are 1 answers

2
glytching On BEST ANSWER

In terms of configuring Logback, there is no difference. Both of the following declarations are functionally identical:

<logger name="com.x.y">
    <level value="DEBUG"/>
</logger>

<logger name="com.x.y" level="DEBUG" />

Logback's configurer (have a look at ch.qos.logback.core.joran.GenericConfigurator.doConfigure()) creates an identical Logger instance for both of these declarations.

The only difference - when parsing the configuration - is that the first one manifests in more instances of ch.qos.logback.core.joran.event.SaxEvent (start and end events for the logger and for the level) than the second one (start and end events for the logger only).

If you are associating a logger with a specific appender then you'll already be defining a logger element body e.g.

<logger name="com.x.y">
    <appender-ref ref="STDOUT"/>
</logger>

In which case defining a level within the element body rather than as an attribute might read better but it really is just a case of developer preference.