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 ?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With