[logback-user] [Sifting Appender ] Programmatically
M. MychaL
mychal.13 at gmail.com
Mon Mar 4 11:34:33 CET 2013
Plz, need help on this subject....
Is it possible to attach the fileappender to the siftingappender exactly as
in XML configuration ?
Thank you.
2013/2/14 M. MychaL <mychal.13 at gmail.com>
> *How do you create a siftingappender with a fileappender manually ?*
>
>
>
> *Here my code :*
>
>
>
> LoggerContext loggerContext = (LoggerContext)
> LoggerFactory.getILoggerFactory();
>
>
>
> PatternLayoutEncoder encoder = new PatternLayoutEncoder();
>
> encoder.setContext(loggerContext);
>
> encoder.setPattern("<%d(yyyy-MM-dd HH:mm:ss=> | %.-1level | %msg
> %n");
>
> encoder.start();
>
>
>
> FileAppender<ILoggingEvent> fAppender = new FileAppender<ILoggingEvent>();
>
> fAppender.setContext(loggerContext);
>
> fAppender.setName(application + "_" + user);
>
> fAppender.setFile(logUser);
>
> fAppender.setAppend(true);
>
> fAppender.setEncoder(encoder);
>
> fAppender.start();
>
>
>
> MDCBasedDiscriminator discriminator = new MDCBasedDiscriminator();
>
> discriminator.setKey("userid");
>
> discriminator.setDefaultValue("unknown");
>
> discriminator.start();
>
>
>
> LevelFilter lFilter = new LevelFilter();
>
> lFilter.setLevel(Level.INFO);
>
> lFilter.start();
>
>
>
> // HOW TO ATTACH fAppender on sAppender ????
>
> SiftingAppender sAppender = new SiftingAppender();
>
> sAppender.setContext(loggerContext);
>
> sAppender.setName(application + "_" + user + "_SIFTING");
>
> sAppender.addFilter(lFilter);
>
> sAppender.setDiscriminator(discriminator);
>
> sAppender.start();
>
>
>
> Logger logger = loggerContext.getLogger("test.mypackage");
>
> logger.setAdditive(false);
>
> logger.setLevel(Level.ALL);
>
> logger.addAppender(sAppender);
>
>
>
>
>
> Thank you….
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20130304/94ffd84b/attachment.html>
More information about the Logback-user
mailing list