[logback-user] Split logs to different files by MDC?

Yura Levandovskyy liova_89 at yahoo.ca
Thu Jun 14 16:15:13 CEST 2012


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 at qos.ch>
To: logback users list <logback-user at 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 at qos.ch>
> *To:* logback users list <logback-user at 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 at 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 at qos.ch
http://mailman.qos.ch/mailman/listinfo/logback-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120614/03c55530/attachment.html>


More information about the Logback-user mailing list