Split logs to different files by MDC?

Hello I have an application that has an mdc variable. How can I make a proper filter, so that if variable = test, all such output goes to one file, and to another file if variable is anything else? I tried the following (not sure how to go from there even if it worked though): <expression> mdc?.get("variable") ~= /test/ </expression> but the result is ERROR in ch.qos.logback.classic.boolex.JaninoEventEvaluator@7d55b9f - Could not start evaluator with expression [mdc?.get("variable") ~= /test/ )] Any suggestions? Thanks

I'd suggest to re-write the expression as ((String))mdc.get("variable").matches("/test/") Are you familiar with SiftingAppender? It seems to address a use case similar to yours. HTH, [1] http://logback.qos.ch/manual/appenders.html#SiftingAppender -- Ceki http://twitter.com/#!/ceki On 12.06.2012 20:17, Yura Levandovskyy wrote:
Hello
I have an application that has an mdc variable. How can I make a proper filter, so that if variable = test, all such output goes to one file, and to another file if variable is anything else?
I tried the following (not sure how to go from there even if it worked though):
<expression> mdc?.get("variable") ~= /test/ </expression>
but the result is
ERROR in ch.qos.logback.classic.boolex.JaninoEventEvaluator@7d55b9f - Could not start evaluator with expression [mdc?.get("variable") ~= /test/ )]
Any suggestions?
Thanks

Great, SiftingAppender seems to be what I need, once I can configure it correctly Could you assist with rolling policy for it? I have a rolling policy that rolls over on size. Whether I put it in the sifting appender (<appendername="SIFT"class="ch.qos.logback.classic.sift.SiftingAppender">) or one of the generated ones (<appendername="FILE-${userid}"class="ch.qos.logback.core.FileAppender">) it seems to have no effect in either case. The rolling policy works fine in a separate FileAppender. Is it possible to add a rolling policy for a sifting appender, am I missing something? Thank you. ________________________________ From: ceki <ceki@qos.ch> To: logback users list <logback-user@qos.ch> Sent: Tuesday, June 12, 2012 4:00:28 PM Subject: Re: [logback-user] Split logs to different files by MDC? I'd suggest to re-write the expression as ((String))mdc.get("variable").matches("/test/") Are you familiar with SiftingAppender? It seems to address a use case similar to yours. HTH, [1] http://logback.qos.ch/manual/appenders.html#SiftingAppender -- Ceki http://twitter.com/#!/ceki On 12.06.2012 20:17, Yura Levandovskyy wrote:
Hello
I have an application that has an mdc variable. How can I make a proper filter, so that if variable = test, all such output goes to one file, and to another file if variable is anything else?
I tried the following (not sure how to go from there even if it worked though):
<expression> mdc?.get("variable") ~= /test/ </expression>
but the result is
ERROR in ch.qos.logback.classic.boolex.JaninoEventEvaluator@7d55b9f - Could not start evaluator with expression [mdc?.get("variable") ~= /test/ )]
Any suggestions?
Thanks
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

SiftingAppender can contain any other appenders except another SiftingAppender. Can you post your config file? On 13.06.2012 23:47, Yura Levandovskyy wrote:
Great, SiftingAppender seems to be what I need, once I can configure it correctly
Could you assist with rolling policy for it? I have a rolling policy that rolls over on size. Whether I put it in the sifting appender (*<appendername="SIFT"class="ch.qos.logback.classic.sift.SiftingAppender">) * or one of the generated ones* * *(**<appendername="FILE-${userid}"class="ch.qos.logback.core.FileAppender">)* it seems to have no effect in either case. The rolling policy works fine in a separate FileAppender. Is it possible to add a rolling policy for a sifting appender, am I missing something?
Thank you.
------------------------------------------------------------------------ *From:* ceki <ceki@qos.ch> *To:* logback users list <logback-user@qos.ch> *Sent:* Tuesday, June 12, 2012 4:00:28 PM *Subject:* Re: [logback-user] Split logs to different files by MDC?
I'd suggest to re-write the expression as
((String))mdc.get("variable").matches("/test/")
Are you familiar with SiftingAppender? It seems to address a use case similar to yours. HTH,
[1] http://logback.qos.ch/manual/appenders.html#SiftingAppender
-- Ceki http://twitter.com/#!/ceki <http://twitter.com/#%21/ceki>
On 12.06.2012 20:17, Yura Levandovskyy wrote:
Hello
I have an application that has an mdc variable. How can I make a proper filter, so that if variable = test, all such output goes to one file, and to another file if variable is anything else?
I tried the following (not sure how to go from there even if it worked though):
<expression> mdc?.get("variable") ~= /test/ </expression>
but the result is
ERROR in ch.qos.logback.classic.boolex.JaninoEventEvaluator@7d55b9f - Could not start evaluator with expression [mdc?.get("variable") ~= /test/ )]
Any suggestions?
Thanks
-- Ceki http://twitter.com/#!/ceki

This is the appender in question: <appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender"> <discriminator> <key>variable</key> <defaultValue>default</defaultValue> </discriminator> <sift> <appender name="FILE-${variable}" class="ch.qos.logback.core.FileAppender"> <file>${home}/logs/${variable}.log</file> <append>false</append> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern>[%X{variable}]</pattern> </layout> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${home}/logs/${variable}.%d{yyyy-MM-dd}.%d{HHmm,aux}.%i.log</fileNamePattern> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATPExt"> <maxFileSize>50KB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> <maxHistory>30</maxHistory> </rollingPolicy> </appender> </sift> </appender> ________________________________ From: ceki <ceki@qos.ch> To: logback users list <logback-user@qos.ch> Sent: Wednesday, June 13, 2012 5:49:31 PM Subject: Re: [logback-user] Split logs to different files by MDC? SiftingAppender can contain any other appenders except another SiftingAppender. Can you post your config file? On 13.06.2012 23:47, Yura Levandovskyy wrote:
Great, SiftingAppender seems to be what I need, once I can configure it correctly
Could you assist with rolling policy for it? I have a rolling policy that rolls over on size. Whether I put it in the sifting appender (*<appendername="SIFT"class="ch.qos.logback.classic.sift.SiftingAppender">) * or one of the generated ones* * *(**<appendername="FILE-${userid}"class="ch.qos.logback.core.FileAppender">)* it seems to have no effect in either case. The rolling policy works fine in a separate FileAppender. Is it possible to add a rolling policy for a sifting appender, am I missing something?
Thank you.
------------------------------------------------------------------------ *From:* ceki <ceki@qos.ch> *To:* logback users list <logback-user@qos.ch> *Sent:* Tuesday, June 12, 2012 4:00:28 PM *Subject:* Re: [logback-user] Split logs to different files by MDC?
I'd suggest to re-write the expression as
((String))mdc.get("variable").matches("/test/")
Are you familiar with SiftingAppender? It seems to address a use case similar to yours. HTH,
[1] http://logback.qos.ch/manual/appenders.html#SiftingAppender
-- Ceki http://twitter.com/#!/ceki <http://twitter.com/#%21/ceki>
On 12.06.2012 20:17, Yura Levandovskyy wrote: > Hello > > I have an application that has an mdc variable. How can I make a proper > filter, so that if variable = test, all such output goes to one file, > and to another file if variable is anything else? > > I tried the following (not sure how to go from there even if it worked > though): > > <expression> > mdc?.get("variable") ~= /test/ > </expression> > > but the result is > > ERROR in ch.qos.logback.classic.boolex.JaninoEventEvaluator@7d55b9f - > Could not start evaluator with expression [mdc?.get("variable") ~= /test/ )] > > Any suggestions? > > Thanks >
-- Ceki http://twitter.com/#!/ceki _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

Hi Yura, There multiple errors in the config you provided (independent of SiftingAppender). As a general recommendation, you should set the debug attribute to true to see the errors. <configuration debug="true"> ... </configuration? Here are a few hints. Hint1: ch.qos.logback.core.rolling.RollingFileAppender not FileAppender Hint2: SizeAndTimeBasedFNATPExt does not exist HTH, -- Ceki http://twitter.com/#!/ceki On 14.06.2012 16:15, Yura Levandovskyy wrote:
This is the appender in question:
<appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender"> <discriminator> <key>variable</key> <defaultValue>default</defaultValue> </discriminator> <sift> <appender name="FILE-${variable}" class="ch.qos.logback.core.FileAppender"> <file>${home}/logs/${variable}.log</file> <append>false</append> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern>[%X{variable}]</pattern> </layout> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${home}/logs/${variable}.%d{yyyy-MM-dd}.%d{HHmm,aux}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATPExt"> <maxFileSize>50KB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> <maxHistory>30</maxHistory> </rollingPolicy> </appender> </sift> </appender>

By the way, since the home property is used within SiftingAppender, it should be defined in the "context" scope. Example: <property name="home" value="/tmp" scope="context"/> HTH, -- Ceki http://twitter.com/#!/ceki On 14.06.2012 18:57, ceki wrote:
Hi Yura,
There multiple errors in the config you provided (independent of SiftingAppender). As a general recommendation, you should set the debug attribute to true to see the errors.
<configuration debug="true"> ... </configuration?
Here are a few hints.
Hint1: ch.qos.logback.core.rolling.RollingFileAppender not FileAppender Hint2: SizeAndTimeBasedFNATPExt does not exist
HTH,

Oh wow, I actually haven't noticed that I just have FileAppender, not RollingFileAppender The 'home' property is defined higher up, so that part works well now Thank you for the hint about debug, going to save a lot of frustration Could you advise on how to use <if> with mdc values? What I'm trying is the following: I have this in my SiftingAppender: <discriminator> <key>variable</key> <defaultValue>default</defaultValue> </discriminator> I want to determine the file name depending on the property, such that (inside rollingPolicy): <if condition='property("variable").equals("default")'> <then> <fileNamePattern>${home}/logs/generic-logs.%d{yyyy-MM}.%i.log</fileNamePattern> </then> <else> <fileNamePattern>${home}/logs/${variable}.%d{yyyy-MM-dd}.%d{HHmm,aux}.%i.log</fileNamePattern> </else> </if> At the moment the .equals check seems to fail all the time, and so the 1st fileNamePattern is never used. What am I doing wrong? ________________________________ From: ceki <ceki@qos.ch> To: logback users list <logback-user@qos.ch> Sent: Thursday, June 14, 2012 1:02:19 PM Subject: Re: [logback-user] Split logs to different files by MDC? By the way, since the home property is used within SiftingAppender, it should be defined in the "context" scope. Example: <property name="home" value="/tmp" scope="context"/> HTH, -- Ceki http://twitter.com/#!/ceki On 14.06.2012 18:57, ceki wrote:
Hi Yura,
There multiple errors in the config you provided (independent of SiftingAppender). As a general recommendation, you should set the debug attribute to true to see the errors.
<configuration debug="true"> ... </configuration?
Here are a few hints.
Hint1: ch.qos.logback.core.rolling.RollingFileAppender not FileAppender Hint2: SizeAndTimeBasedFNATPExt does not exist
HTH,
Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

SiftingAppender replays elements found within <sift>...</sift> when it creates a new appender instance. You probably do not want SiftingAppender to do conditional configuration each time it creates a new appender. As such, I would remommend to move the conditional part outside the <sift></sift> element. Is that possible? -- Ceki http://twitter.com/#!/ceki On 15.06.2012 20:26, Yura Levandovskyy wrote:
Oh wow, I actually haven't noticed that I just have FileAppender, not RollingFileAppender The 'home' property is defined higher up, so that part works well now Thank you for the hint about debug, going to save a lot of frustration
Could you advise on how to use <if> with mdc values? What I'm trying is the following:
I have this in my SiftingAppender: <discriminator> <key>variable</key> <defaultValue>default</defaultValue> </discriminator>
I want to determine the file name depending on the property, such that (inside rollingPolicy):
<if condition='property("variable").equals("default")'> <then> <fileNamePattern>${home}/logs/generic-logs.%d{yyyy-MM}.%i.log</fileNamePattern>
</then> <else> <fileNamePattern>${home}/logs/${variable}.%d{yyyy-MM-dd}.%d{HHmm,aux}.%i.log</fileNamePattern> </else> </if>
At the moment the .equals check seems to fail all the time, and so the 1st fileNamePattern is never used. What am I doing wrong?
------------------------------------------------------------------------ *From:* ceki <ceki@qos.ch> *To:* logback users list <logback-user@qos.ch> *Sent:* Thursday, June 14, 2012 1:02:19 PM *Subject:* Re: [logback-user] Split logs to different files by MDC?
By the way, since the home property is used within SiftingAppender, it should be defined in the "context" scope. Example:
<property name="home" value="/tmp" scope="context"/>
HTH, -- Ceki http://twitter.com/#!/ceki <http://twitter.com/#%21/ceki>
On 14.06.2012 18:57, ceki wrote:
Hi Yura,
There multiple errors in the config you provided (independent of SiftingAppender). As a general recommendation, you should set the debug attribute to true to see the errors.
<configuration debug="true"> ... </configuration?
Here are a few hints.
Hint1: ch.qos.logback.core.rolling.RollingFileAppender not FileAppender Hint2: SizeAndTimeBasedFNATPExt does not exist
HTH,

Is it possible to define appender's FileNamePattern from outside of it? If I'm outside the <sift></sift> element I'm also outside of the appender too. ________________________________ From: ceki <ceki@qos.ch> To: logback users list <logback-user@qos.ch> Sent: Friday, June 15, 2012 3:59:51 PM Subject: Re: [logback-user] Split logs to different files by MDC? SiftingAppender replays elements found within <sift>...</sift> when it creates a new appender instance. You probably do not want SiftingAppender to do conditional configuration each time it creates a new appender. As such, I would remommend to move the conditional part outside the <sift></sift> element. Is that possible? -- Ceki http://twitter.com/#!/ceki On 15.06.2012 20:26, Yura Levandovskyy wrote:
Oh wow, I actually haven't noticed that I just have FileAppender, not RollingFileAppender The 'home' property is defined higher up, so that part works well now Thank you for the hint about debug, going to save a lot of frustration
Could you advise on how to use <if> with mdc values? What I'm trying is the following:
I have this in my SiftingAppender: <discriminator> <key>variable</key> <defaultValue>default</defaultValue> </discriminator>
I want to determine the file name depending on the property, such that (inside rollingPolicy):
<if condition='property("variable").equals("default")'> <then> <fileNamePattern>${home}/logs/generic-logs.%d{yyyy-MM}.%i.log</fileNamePattern>
</then> <else> <fileNamePattern>${home}/logs/${variable}.%d{yyyy-MM-dd}.%d{HHmm,aux}.%i.log</fileNamePattern> </else> </if>
At the moment the .equals check seems to fail all the time, and so the 1st fileNamePattern is never used. What am I doing wrong?
------------------------------------------------------------------------ *From:* ceki <ceki@qos.ch> *To:* logback users list <logback-user@qos.ch> *Sent:* Thursday, June 14, 2012 1:02:19 PM *Subject:* Re: [logback-user] Split logs to different files by MDC?
By the way, since the home property is used within SiftingAppender, it should be defined in the "context" scope. Example:
<property name="home" value="/tmp" scope="context"/>
HTH, -- Ceki http://twitter.com/#!/ceki <http://twitter.com/#%21/ceki>
On 14.06.2012 18:57, ceki wrote: > Hi Yura, > > There multiple errors in the config you provided (independent of > SiftingAppender). As a general recommendation, you should set the > debug attribute to true to see the errors. > > <configuration debug="true"> > ... > </configuration? > > Here are a few hints. > > Hint1: ch.qos.logback.core.rolling.RollingFileAppender not FileAppender > Hint2: SizeAndTimeBasedFNATPExt does not exist > > HTH,
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
participants (2)
-
ceki
-
Yura Levandovskyy