1

It seems to me that what I am trying to achieve is very common but I don't get it to work:

I have one appender for the root logger that just logs anything that bubbles up to the root. And I have another appender attached to a more specific logger. The specific logger has level INFO but I'd like only ERROR messages to bubble up to the root. What is the best way to achieve this?

The root logger may log INFO messages passed from other specific loggers but for this particular logger I don't want any INFO messages to be passed up the hierarchy.

lex82
  • 11,173
  • 2
  • 44
  • 69

1 Answers1

1

logback: Two appenders, multiple loggers, different levels <- The first answer here should have what you need. it describes a custom ThresholdLoggerFilter, which can be used on the appender of your root to filter messages based on both their origin (Logger) and level threshold. Then you simply filter out anything but ERROR for the logger you do not want to see anything else from:

<appender name="RootAppender" class="ch.qos.logback.core.ConsoleAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>INFO</level>
    </filter>
    <filter class="com.myapp.ThresholdLoggerFilter">
        <logger>TheLoggerFromWhichYouWantOnlyErrorOnTheRoot</logger>
        <level>ERROR</level>
    </filter>
</appender>

Turns out it's actually not THAT common or easy a use case, but it's possible.

Community
  • 1
  • 1
sheltem
  • 3,754
  • 1
  • 34
  • 39
  • Thanks. I already found that one but I was hoping there was a simpler solution without custom Filter. I also don't like that it depends on the appender. My root logger has two appenders, so I will have to add the filter to both. It would be nicer to suppress the non-error events at the level of the specific logger. However, thank you for your help! – lex82 Aug 28 '14 at 14:10