[logback-user] Job Logger configuration
David Roussel
nabble at diroussel.xsmail.com
Fri Oct 11 11:35:29 CEST 2013
Matt,
You can do this. I've done it.
First thing to note is that sifting appender only works off one key. So in your code concatenate the folder, sub folder and filename into one value and stick that in the MDC and use it as the key to the sifter and the variable in the path.
Next to make the log items only appear in one log I used two filters. One on the main log and one of the sifter. Make sure the two filters work opposed to each other. So when one accepts the other rejects.
Ideally there would be a switching filter, but it doesn't exist.
David
> On 11 Oct 2013, at 02:18, Matt Young <solid at youngdev.net> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> OK so I am working on a custom job engine and I am trying to separate my
> job logs from the main application logs as well as separating the logs
> for each individual job run from each other. My plan is to
> use the sifting log appender to put the logs into a hierarchy on the
> filesystem as the
> {job_group}/{job_name}/{instance_id}
> I know I can pull multiple values out of the MDC for use in the pattern
> layout but I am having trouble using them in the filename.
> I am not sure my above approach will work for directory names but
> according to the docs it should work at least for the filename.
>
> My second question is how do I keep my job logs out of the main log?
>
> Here is my current config:
> <?xml version="1.0" encoding="UTF-8"?>
>
> <configuration>
>
> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
> <!-- encoders are assigned the type
> ch.qos.logback.classic.encoder.PatternLayoutEncoder by
> default -->
> <encoder>
> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %C:%L
> %msg%n</pattern>
> </encoder>
> </appender>
> <appender name="jobLoggerAppender"
> class="ch.qos.logback.classic.sift.SiftingAppender">
> <sift>
> <appender name="FILE-${jobId}"
> class="ch.qos.logback.core.FileAppender">
> <file>${jobGroup}-${jobId}.log</file>
> <layout class="ch.qos.logback.classic.PatternLayout">
> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level
> [%thread] %C:%L %msg%n</pattern>
> </layout>
> </appender>
> </sift>
> </appender>
>
>
> <logger name="com.lordofthejars.foo" level="INFO" additivity="false">
> <appender-ref ref="STDOUT" />
> </logger>
>
> <!-- Strictly speaking, the level attribute is not necessary since -->
> <!-- the level of the root level is set to DEBUG by default. -->
> <root level="DEBUG"> <appender-ref ref="STDOUT" />
>
> </root>
> <logger name="jobLogger" level="debug">
> <appender-ref ref="jobLoggerAppender"/>
> </logger>
> </configuration>
>
> - --
> Cheers,
> Matt Young
> solid at youngdev.net
> http://youngdev.net
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iQIcBAEBAgAGBQJSV1HSAAoJEO5jycTTPEzc/0IP/Rr48HksJFgSDg2iSUIsOL6X
> arJ/VADWDWG+4ydApy+Gw5B5Zx1D8Ds6TQzKB9rSX2lXOJoO/zRb/ObF6eOx8d9t
> koVSO7bG9foID/DUm29cGm7ne11yA06EmYyxjJQ0e8TD6ixxIPyiQIOr1cfvRT0/
> e3mkrH+xJUByXmRu9elsOzDYk1xqwIRY6I5KcB1g3/2NxOTjG8DL7n3WTcKbea0t
> g0QOlFv5jLwsxa5l0SDn2ONtV+QipS/ecvTdnH+bk7FvY5bX0UcEURfQcKiMK9Sl
> fozS+AeukrBi4W72iVFYeQxxaYpJyEqRp457yq++wPGbeJP8w0cn7Cke9a8i9M7h
> pudRazu6MXF1u9c2kWscCugdpHAcEA+HXS94Ah5RlXkX9VBqKoc2pjrzx+wrZcCh
> nAODUWdFx8C654hmjFSD0oUKNaG5WEwJbQaAwFCrOdlB31Teeqw10e3ArcI/D9OL
> dnWFXGdD/QKKoCfgMCs3nFhPDmGuMzcBDopR5bxF5DDspoALxiHbLS6eRIXhYH+i
> aieeERi4GnJsCRfCVJbqK4qOq2ePuwi8HDptRNTv8HiHmC4uNz51k/VL0cqHpjlw
> 8ZrSUFAe4h6D7TsrLJ9ehac8J1QlAtycq1MX/4fleWXf2dK53kgNBbPDNBQsV2lZ
> X34Ooo+zOV15p7ijQ2en
> =mdwF
> -----END PGP SIGNATURE-----
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
More information about the Logback-user
mailing list