We know that logger
inherits the root
's configurations in Logback.
For example:
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
<logger name="com.thinkaurelius.thrift" level="ERROR"/>
<logger name="org.apache.cassandra.transport" level="DEBUG">
<appender-ref ref="QUERYLOGGER" />
</logger>
In this logback.xml
, we defined a root
which has two appenders:
FILE
(redirect output to a file) STDOUT
(terminal printer)We also add two loggers
in which we defined some customized logging level and customized appender. For example: all DEBUG log will go to QUERYLOGGER appender (which is the other file on disk) for org.apache.cassandra.transport
However, all the debug info of org.apache.cassandra.transport
also appear in STDOUT
and FILE
because it inherits the config from root
.
What if I want to disable STDOUT
and FILE
appender but keep QUERYLOGGER
appender for only org.apache.cassandra.transport
logger?
After reading the documentation of logback. I myself found the answer towards this specific question:
<logger>
tag supports an attribute called additivity
which by defaults is set to true
. Turn this value to false
will prevent this logger from inheriting from parents.
For this case:
<logger name="org.apache.cassandra.transport" level="DEBUG" additivity='false'>
<appender-ref ref="QUERYLOGGER" />
</logger>
Logback additivity example
Logback 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