Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does logback have a NullAppender?

I know there is a NullAppender in log4j. But I can't find the appender in logback. Is there a better way for ignoring all logs in logback?

like image 780
DeepNightTwo Avatar asked Jul 12 '13 08:07

DeepNightTwo


2 Answers

This is an old question, but the answers already given do not actually answer it.

Yes

There is a "null" appender, but that is not what it is called. I believe the logback author prefers the term "no-op" when referring to implementations that exist to satisfy some compile, test, or other design requirements, but do not actually perform any operation. The appender implementation that was originally asked about is:

ch.qos.logback.core.helpers.NOPAppender

javadoc

source

like image 192
ZachOfAllTrades Avatar answered Oct 06 '22 00:10

ZachOfAllTrades


To add to ZachOfAllTrades' answer, here is a example logback.xml that sets the root log level to INFO but uses the NOPAppender to log everything to nirvana:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appender name="NOP" class="ch.qos.logback.core.helpers.NOPAppender"/>
  <root level="INFO">
    <appender-ref ref="NOP"/>
  </root>
</configuration>
like image 26
Sebastian Avatar answered Oct 05 '22 22:10

Sebastian