Reputation: 2673
referring to: Logback's Configuration
my configuration can contain
...at most one <root> element...
but then later in the same doc, when discussing conditionals, I see this:
<configuration debug="true">
<if condition='property("HOSTNAME").contains("torino")'>
<then>
<appender name="CON" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>
<root> <------ root logger #1
<appender-ref ref="CON" />
</root>
</then>
</if>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${randomOutputDir}/conditional.log</file>
<encoder>
<pattern>%d %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>
<root level="ERROR"> <------ root logger #2
<appender-ref ref="FILE" />
</root>
</configuration>
Notice there are TWO <root>
elements! I'm very confused because I don't see any <else>
elements and I would assume the FILE appender and the second root logger are still in play, even if the hostname was "torino".
How is this a valid example? Why are two <root>
loggers allowed in this case when one is not within an <if>
or an <else>
what am I missing???
Upvotes: 5
Views: 2960
Reputation: 27490
Disclaimer: I am the maintainer of the logback project.
This definitely deserves a clarification in the logback documentation. Can you please file a bug report at http://jira.qos.ch ? Referencing this StackOverflow entry should be enough.
As for which root logger is active, assuming the conditional is true, they will be both active. Both appenders named FILE and CON would be attached to the root logger. The level would be set to the last value set. Note that the root element within the conditional does not set a level.
Upvotes: 6