How to configure Logback to filter out anything that does not have a specific marker

This must be a simple thing, but I am not getting it. I have a marker, say "performance" that I use when logging. Also, I often use isDebugEnabled() etc. when log messages become expensive to build. Now I want to configure logback that I can do these two things: 1) Log all statements in Logger foo.Bar that are debug or higher and use the marker "performance" 2) Log all statements across all Loggers that use the marker "performance" To achieve 1) I tried this: <turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter"> <Marker>index-control-flow</Marker> <OnMatch>ACCEPT</OnMatch> </turboFilter> <logger name="foo.Bar" level="DEBUG"/> Then also all log messages that are not tagged with this marker appear in the log. To achieve 2) I tried omitting the logger line above and got only log messages with the marker, however, all log messages protected by a check of isDebugEnabled() are omitted. I must be missing a general concept here. Thanks in advance, Robert

My first reaction is to say stop using isDebugEnabled(). You shouldn't need to do that. But if you really must, then try using isDebugEnabled(Marker) with debug(Marker,...). Hope this helps, Paul
On Jul 26, 2015, at 09:00, Robert Krüger <krueger@lesspain.de> wrote:
This must be a simple thing, but I am not getting it.
I have a marker, say "performance" that I use when logging. Also, I often use isDebugEnabled() etc. when log messages become expensive to build.
Now I want to configure logback that I can do these two things:
1) Log all statements in Logger foo.Bar that are debug or higher and use the marker "performance"
2) Log all statements across all Loggers that use the marker "performance"
To achieve 1) I tried this:
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter"> <Marker>index-control-flow</Marker> <OnMatch>ACCEPT</OnMatch> </turboFilter>
<logger name="foo.Bar" level="DEBUG"/> Then also all log messages that are not tagged with this marker appear in the log.
To achieve 2) I tried omitting the logger line above and got only log messages with the marker, however, all log messages protected by a check of isDebugEnabled() are omitted.
I must be missing a general concept here.
Thanks in advance,
Robert _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

On Sun, Jul 26, 2015 at 4:00 PM, Paul Krause <pkrause@investsoftech.com> wrote:
My first reaction is to say stop using isDebugEnabled(). You shouldn't need to do that.
Maybe in some cases its overkill but in some cases I build more expensive data structures/representations only for logging which I need to avoid when logging with fine granularity in performance-critical area
But if you really must, then try using isDebugEnabled(Marker) with debug(Marker,...).
Great, that solves one of my problems. The only remaining one I have also solved. I did non stumble accross the "OnMismatch" directive until now. Changing my example to this here, <turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter"> <Marker>performance</Marker> <OnMismatch>DENY</OnMismatch> </turboFilter> together with isDebugEnabled(Marker) and setting the levels of the individual loggers gives me the solution to 1) (not exactly but good enough) and the same with OnMatch ACCEPT gives me the setup for 2)
Hope this helps, Paul
It sure did. Thanks a lot! Robert
participants (2)
-
Paul Krause
-
Robert Krüger