<span style>Hi Ceki,</span><div style><br></div><div style>Thanks for your prompt response. I wasn't aware of routing appenders - so this is something that I shall certainly look into. My main motivation for wanting to do this was primarily so that I could control the verboseness of logging for the same logger depending on the destination appender without having to create several (almost duplicate) appender configurations (whilst setting slightly different threshold levels for each) - as far as possible I only wanted to create a single appender configuration entry for each distinct destination - i.e. Console, RollingFile etc. So, for example, I might have a logger in a Java class which generates log messages of varying levels, but I only want INFO and above to go to a Console appender, whilst I want DEBUG and above to be written to a RollingFileAppender - for the same class - simply because I don't want to clog up STDOUT with too much information (unless I need to) but have a separate file to fall back to which does contain a complete set of log messages for reference/debug at a later date.</div>
<div style><br></div><div style>Is there any documentation describing how to create routing appenders (I had a quick look and couldn't see anything) or is there an example of such an appender lurking somewhere within the source that you could point me towards?</div>
<div style><br></div><div style>Regards,</div><div style><br></div><div style>Shane</div>
<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><br>
Hello Shane,<br>
<br>
There are probably multiple approaches to this problem. It should be not too difficult to write a RoutingAppender which can perform the type of routing operation you describe. Here is how the config file would look like:<br>
<br>
<appender name="A"></appender><br>
<appender name="B"></appender><br>
<br>
<appender name="ROUTING-ONE" class="...RoutingAppender"><br>
<reference name="A" level="INFO"/><br>
<reference name="B" level="DEBUG"/><br>
</appender><br>
<br>
<appender name="ROUTING-TWO" class="...RoutingAppender"><br>
<reference name="A" level="WARN"/><br>
<reference name="B" level="TRACE"/><br>
</appender><br>
<br>
<logger name="com.myorg.myapp.<u></u>subpackage.one"><br>
<appender-ref ref="ROUTING-ONE"/><br>
</logger><br>
<br>
<logger name="com.myorg.myapp.<u></u>subpackage.two"><br>
<appender-ref ref="ROUTING-TWO"/><br>
</logger><br>
<br>
<br>
By the way, could you provide more detail for your use case?<br>
<br>
Cheers,<br>
-- <br>
Ceki<br>
<a href="http://twitter.com/#!/ceki" target="_blank">http://twitter.com/#!/ceki</a><div><div><div><div><br>
<br>
On 05.05.2012 22:48, Shane Kelly wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Folks,<br>
<br>
I've been tinkering with both log4j and more recently logback and I was<br>
wondering whether or not it is possible to configure it in such a way<br>
that it would be possible for a single logger to write to multiple<br>
appenders using different LEVEL restrictions on a per-appender-ref<br>
basis. I appreciate that it is possible to specify a LEVEL attribute for<br>
each individual logger - but then any message which meets the logger<br>
LEVEL criteria will be sent to all referenced appenders. I'm also aware<br>
that you can define level thresholds and filters on a per-appender basis<br>
- but what I was hoping for was rather than define lots of very similar<br>
appender configurations (each with slightly different thresholds) that I<br>
could define a smaller number of core appenders and have messages of<br>
certain levels filtered out even before the appender is called.<br>
<br>
To help illustrate the concept I'm aiming for, I've included a<br>
pseudo-configuration file below. You'll notice that I've omitted the<br>
LEVEL attribute from the <logger/> nodes and added LEVEL attributes to<br>
each of the <appender-ref> nodes - this doesn't work obviously, but I<br>
was wondering if there was some other way of emulating the behaviour<br>
that I'm after without cluttering up the logback configuration too<br>
much...? You can see from the configuration that for<br>
com.myorg.myapp.subpackage.one I would like to apply different log level<br>
restrictions depending on the destination appender. You'll also notice<br>
that for com.myorg.myapp.subpackage.two I want to reuse the same<br>
appenders, but also use different level restrictions.... hope that makes<br>
it clear enough...<br>
<br>
---------<br>
<br>
<appender name="A"><br>
...<br>
...<br>
</appender><br>
<br>
<appender name="B"><br>
...<br>
...<br>
</appender><br>
<br>
<logger name="com.myorg.myapp.<u></u>subpackage.one"><br>
<appender-ref ref="A" LEVEL="INFO"/><br>
<appender-ref ref="B" LEVEL="DEBUG"/><br>
</logger><br>
<br>
<logger name="com.myorg.myapp.<u></u>subpackage.two"><br>
<appender-ref ref="A" LEVEL="WARN"/><br>
<appender-ref ref="B" LEVEL="TRACE"/><br>
</logger><br>
<br>
----------<br>
<br>
Regards,<br>
<br>
Shane<br>
<br>
</blockquote>
<br></div></div></div></div>
______________________________<u></u>_________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/<u></u>listinfo/logback-user</a><br>
</div><br>
</blockquote></div><br>