[logback-user] Dynamically attaching the loggers to appenders

Pradnya Gawade pradnya.gawade7 at gmail.com
Fri Dec 3 00:16:08 CET 2010

Hi, I am having the issue described below, sorry for the long post but
I think that is required to better explain the problem.

I want to separate out the logs in such a way that some special
packages, classes needs to go in specific log format and rest of the
logs will go in default format. I have created the multiple file,
Syslog appenders with all the required formats. But I am having
difficulty configuring in such a way that the log messages from
packages other than my special packages will go with the default
appender. Initially my idea was to map the basic outer package to all
the special appenders as well as to default appender, create a filter
for each special appender so it will only take the specific package
logs only. But the problem is that default appender takes all the log
messages. I can again implement a filter for the default appender so
it will take all the excluded log s only but probably it it will be
lot of processing unnecessarily, evaluating the same criteria again
and again for each logging request. Is there any way so I can
intercept each logging request such that I can decide which appender I
need this logger to map to (by implementing some java routine), put
the result in MDC context and make use of that result variable in the
configuration to associate the required appender (using if-else
syntax)? I saw that Sifting appender might be helpful in this scenario
but I don't know where I can put my processing logic to decide which
appender I want the logger to associate to so I can use its result as
discrminator. Any ideas?


More information about the Logback-user mailing list