[logback-user] Setting log LEVEL on a per <appender-ref/> basis

Shane Kelly logback at ballinascreen.com
Sat May 5 22:48:02 CEST 2012


I've been tinkering with both log4j and more recently logback and I was
wondering whether or not it is possible to configure it in such a way that
it would be possible for a single logger to write to multiple appenders
using different LEVEL restrictions on a per-appender-ref basis. I
appreciate that it is possible to specify a LEVEL attribute for each
individual logger - but then any message which meets the logger LEVEL
criteria will be sent to all referenced appenders. I'm also aware that you
can define level thresholds and filters on a per-appender basis - but what
I was hoping for was rather than define lots of very similar appender
configurations (each with slightly different thresholds) that I could
define a smaller number of core appenders and have messages of certain
levels filtered out even before the appender is called.

To help illustrate the concept I'm aiming for, I've included a
pseudo-configuration file below. You'll notice that I've omitted the LEVEL
attribute from the <logger/> nodes and added LEVEL attributes to each of
the <appender-ref> nodes - this doesn't work obviously, but I was wondering
if there was some other way of emulating the behaviour that I'm after
without cluttering up the logback configuration too much...? You can see
from the configuration that for com.myorg.myapp.subpackage.one I would like
to apply different log level restrictions depending on the destination
appender. You'll also notice that for com.myorg.myapp.subpackage.two I want
to reuse the same appenders, but also use different level restrictions....
hope that makes it clear enough...


<appender name="A">

<appender name="B">

<logger name="com.myorg.myapp.subpackage.one">
  <appender-ref ref="A" LEVEL="INFO"/>
  <appender-ref ref="B" LEVEL="DEBUG"/>

<logger name="com.myorg.myapp.subpackage.two">
  <appender-ref ref="A" LEVEL="WARN"/>
  <appender-ref ref="B" LEVEL="TRACE"/>



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120505/6685a103/attachment.html>

More information about the Logback-user mailing list