Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a logger to skip the root section in logback

I have several loggers defined and a root section with several appenders, something like:

  <logger name="X" level="debug"/>
  <logger name="Y" level="trace"/>

  <logger name="Z" level="warn">
    <appender-ref ref="ALERTS-SYSLOG" />
  </logger>

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

What I'm trying to accomplish is for the logger named Z to go only to the ALERTS-SYSLOG appender and not all the ones defined in the root section. Is that possible only with configuration on the XML file?

like image 986
rpvilao Avatar asked May 10 '12 00:05

rpvilao


2 Answers

See logback documentation for appender additivity and for additivity configuration. In short, the Z logger should be configured as:

<!-- set the additivity attribute of the Z logger to false -->
<logger name="Z" level="warn" additivity="false">
  <appender-ref ref="ALERTS-SYSLOG" />
</logger>
like image 160
Ceki Avatar answered Sep 27 '22 23:09

Ceki


Add an entry in the XML file explicitly for logger Z and with the ALERTS_SYSLOG appender and set the additvity flag to false.

like image 33
Sam Avatar answered Sep 27 '22 23:09

Sam