I might be asking something trivial, but what I've tried doesn't seem to work. With my "MAIN" appender, I want to log all "info"s everywhere, except in a third-party package (let's call it boring
), which produces too many of them (so I look at warnings only). Additionally, I want to log "debug"s in my interesting
package. This works fine with the following logback.groovy
:
root(INFO, ["MAIN"])
logger("interesting", DEBUG, ["MAIN"])
logger("boring", WARN, ["MAIN"])
Now I want to configure a different appender logging one level more like
root(DEBUG, ["DETAIL"])
logger("interesting", TRACE, ["DETAIL"])
logger("boring", INFO, ["DETAIL"])
This also works, but when I put both together, it doesn't. I can imagine that this is caused by the fact that each Logger
is either on or off for a given level. I'm aware that for the behavior I want, the loggers in the "boring" package must be on the INFO level (because of the DETAIL
appender) and that the messages for the MAIN
appender are to be filtered, but I can't see how to configure this.
UPDATE
I see I was doing nearly everything wrong. The line
logger("interesting", DEBUG, ["MAIN"])
says nothing like "set the level to DEBUG for the MAIN appender and the package interesting
and below"), it does two independent things instead:
- set the level to DEBUG for the package
interesting
and below - add the MAIN appender to the "interesting"
Logger
This seems to be impossible without writing an own filter, which is fortunately pretty easy. I ended up with something like
where
deny
andaccept
are my methods adding entries toMyFilter
. The entries are evaluated sequentially, i.e.,boring
and below, everything with levelINFO
or below gets deniedinteresting
and below, everything with levelDEBUG
or above gets acceptedDEBUG
or above gets deniedInspired by this question.