Nested sifting appenders

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@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@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@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@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@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

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@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
participants (2)
-
ceki
-
Dario Campagna