Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override Logger's appender inherited from root in Logback [duplicate]

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:

  1. FILE (redirect output to a file)
  2. 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?

like image 793
Ev3rlasting Avatar asked May 03 '18 07:05

Ev3rlasting


1 Answers

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

like image 77
Ev3rlasting Avatar answered Nov 01 '22 14:11

Ev3rlasting