如何配置Logback以将记录器的不同级别记录到不同的目的地?
例如,给定以下Logback配置,Logback会将INFO
消息记录到STDOUT
并将ERROR
消息记录到STDERR
吗?
(请注意,此示例是第3章:Logback配置中logback-examples/src/main/java/chapters/configuration/sample4.xml
所示示例的变形)。
<configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<appender name="STDERR"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
<target>System.err</target>
</appender>
<!-- What is the effective level of "chapters.configuration"? -->
<logger name="chapters.configuration" level="INFO" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<logger name="chapters.configuration" level="ERROR" additivity="false">
<appender-ref ref="STDERR" />
</logger>
<!-- turn OFF all logging (children can override) -->
<root level="OFF">
<appender-ref ref="STDOUT" />
</root>
</configuration>
levels are ordered as follows: TRACE < DEBUG < INFO < WARN < ERROR.