[logback-user] Nested sifting appenders

Dario Campagna campagna at esteco.com
Wed Apr 18 18:00:26 CEST 2012


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.

When I run my application I get the following errors (I omit the full
stack trace of the exception)

17:48:15,213 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
- About to instantiate appender of type
[ch.qos.logback.classic.sift.SiftingAppender]
17:48:15,213 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
- Naming appender as [SIFT-txt]
17:48:15,233 |-INFO in
ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming
default type [ch.qos.logback.classic.sift.MDCBasedDiscriminator] for
[discriminator] property
17:48:15,233 |-INFO in
ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing
component [discriminator] on top of the object stack.
17:48:15,243 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
- Popping appender named [SIFT-txt] from the object stack
17:48:15,243 |-INFO in
ch.qos.logback.classic.joran.action.JMXConfiguratorAction - begin
17:48:15,243 |-INFO in
ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level
of ROOT logger to ALL
17:48:15,243 |-INFO in
ch.qos.logback.core.joran.action.AppenderRefAction - Attaching
appender named [SIFT-txt] to Logger[ROOT]
2012-04-18 17:48:15.823::INFO:  No Transaction manager found - if your
webapp requires one, please configure one.
17:48:15,580 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
- About to instantiate appender of type
[ch.qos.logback.classic.sift.SiftingAppender]
17:48:15,581 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
- Naming appender as [SIFT-Process_0]
17:48:15,581 |-INFO in
ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming
default type [ch.qos.logback.classic.sift.MDCBasedDiscriminator] for
[discriminator] property
17:48:15,581 |-INFO in
ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing
component [discriminator] on top of the object stack.
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]]
17:48:15,582 |-ERROR in
ch.qos.logback.core.joran.spi.Interpreter at 39:87 - no applicable action
for [appender], current pattern is
[[configuration][appender][sift][appender]]
17:48:15,582 |-ERROR in
ch.qos.logback.core.joran.spi.Interpreter at 40:13 - no applicable action
for [file], current pattern is
[[configuration][appender][sift][appender][file]]
17:48:15,582 |-ERROR in
ch.qos.logback.core.joran.spi.Interpreter at 41:15 - no applicable action
for [append], current pattern is
[[configuration][appender][sift][appender][append]]
17:48:15,591 |-INFO in
ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing
component [layout] on top of the object stack.
17:48:15,607 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
- Popping appender named [SIFT-Process_0] from the object stack
17:48:15,607 |-ERROR in
ch.qos.logback.classic.sift.SiftingAppender[SIFT-Process_0] - Appender
[SIFT-Process_0] failed to append. java.lang.NullPointerException
        at java.lang.NullPointerException
        at      at
ch.qos.logback.core.sift.SiftingAppenderBase.append(SiftingAppenderBase.java:79)

I have not been able to discover the cause of the errors. In
particular, I do not understand the following error

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?

Is the nesting of sifting appender in the configuration file allowed?
If it is not allowed, is this limitation mentioned somewhere?


Best regards,
Dario


More information about the Logback-user mailing list