Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback exclude logger from root

I have a few packaged and I want to separate logging.

<property name="A" value="com.a"/>
<property name="B" value="com.b"/>
<property name="C" value="com.c"/>

<logger name="${A}" level="DEBUG">
    <appender-ref ref="FILE_A"/>
</logger>

<logger name="${B}" level="DEBUG">
    <appender-ref ref="FILE_B"/>
</logger>

<logger name="${C}" level="DEBUG">
    <appender-ref ref="FILE_B"/> <!-- yes B -->
</logger>

<root level="DEBUG">      
    <-- used for other logs too ->
    <appender-ref ref="STDOUT"/>
    <appender-ref ref="ROOT_FILE"/>
</root>

So I have FILE_A FILE_B AND ROOT_FILE; ROOT_FILE contains info that writes by root logger and by A B and C loggers.

How I can exclude FILE_A FILE_B info from ROOT_FILE ?

Or in another words how i can exclude log data (com.c com.b com.a) from root logger ?

like image 463
Java Dude Avatar asked Apr 21 '16 23:04

Java Dude


People also ask

How do I disable Logback logging?

Logback does not allow logging to be disabled from the command line. However, if the configuration file allows it, you can set the level of loggers on the command line via a Java system property.

What is root level in Logback?

The possible levels are, in order of precedence: TRACE, DEBUG, INFO, WARN and ERROR. Each level has a corresponding method that we use to log a message at that level. If a Logger isn't explicitly assigned a level, it inherits the level of its closest ancestor. The root logger defaults to DEBUG.

What is additivity false in Logback?

Add additivity="false" to the "AUDIT_LOGGER" , as described in one of the answers above, to not inherit the appenders from the root logger. Remove the appender element from the "AUDIT_LOGGER" . This will cause the "AUDIT_LOGGER" to inherit the appenders from the root logger.


1 Answers

set additivity flag for com.a and com.b loggers to false.

<logger name="${A}" level="DEBUG" additivity="false">
     <appender-ref ref="FILE_A"/>
</logger>

now events logged in that logger won't be propagated to parent loggers (root logger in your case).

documentation

like image 165
user3159253 Avatar answered Sep 22 '22 19:09

user3159253