[logback-user] Nested sifting appenders

ceki ceki at qos.ch
Wed Apr 18 22:59:29 CEST 2012


Hi Dario,

Comments inline.

On 18.04.2012 18:00, Dario Campagna wrote:
> Hi,
>
>     I am Dario Campagna, I am a software developer working for an
> Italian company.
> Few days ago I discovered Logback and started studying it to see if it
> is suitable for the application I am working on.
> In particular, I made some experiments with different appenders and
> layouts defined in a configuration file.
>
> I encountered some problems trying to run the application I am using
> for my experiment with a configuration file that attach to the root
> logger the following sifting appender.
>
> <appender name="SIFT-txt" class="ch.qos.logback.classic.sift.SiftingAppender">
>   <discriminator>
>    <key>parent</key>
>    <defaultValue>unknown</defaultValue>
>   </discriminator>
>   <sift>
>    <appender name="SIFT-${parent}"
> class="ch.qos.logback.classic.sift.SiftingAppender">
>     <discriminator>
>      <key>node</key>
>      <defaultValue>unknown</defaultValue>
>     </discriminator>
>     <sift>
>      <appender name="FILE-${parent}-${node}"
> class="ch.qos.logback.core.FileAppender">
>       <file>${parent}/${node}/log.txt</file>
>       <append>true</append>
>        <layout class="ch.qos.logback.classic.PatternLayout">
>         <pattern>%level%date{ISO8601}: %mdc - %msg%n</pattern>
>        </layout>
>      </appender>
>     </sift>
>    </appender>
>   </sift>
> </appender>
>
> With the above appender I would like to write a log event in a file
> whose path depends on two keys of the mdc.
> The ideas is that the outmost sifting appender discriminates on the
> key named "parent", while the innermost sifting appender discriminates
> on the key named "node". The FileAppender writes log events to a file
> inside the ${parent}/${node} folder.

[cut]

> 17:48:15,581 |-ERROR in
> ch.qos.logback.core.joran.spi.Interpreter at 38:11 - no applicable action
> for [sift], current pattern is [[configuration][appender][sift]]
>
> Isn't the configurator/appender/sift a pattern defined by logback-classic?

Sifting appenders cannot be nested.  The error messages don't make much 
sense. Probably due to the fact that sifting appenders cannot be nested.

> Is the nesting of sifting appender in the configuration file allowed?

No.

> If it is not allowed, is this limitation mentioned somewhere?

No. This is not mentioned in the docs.

Anyway, instead of nesting sifting appender, you should create your own 
discriminator class which merges the values for MDC keys parent and node 
into ${parent}/${node}. Just emulate the code in MDCBasedDiscriminator 
[1]. If you run into trouble ask for help here.

HTH,

[1] http://goo.gl/9KWxK

-- 
Ceki
http://twitter.com/#!/ceki


More information about the Logback-user mailing list