[logback-user] [Sifting Appender ] Programmatically

M. MychaL mychal.13 at gmail.com
Thu Feb 14 10:52:12 CET 2013


*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/20130214/2e9ff6c7/attachment.html>


More information about the Logback-user mailing list