java - Log to a different file according to thread -
i have application multiple "controllers", , i'd have each log own file. easy enough own code, i'm using library code uses commons logging. somehow code log controller-specific file well?
i thinking somehow thread:
class controller { public void action() { setcurrentthreadlogfile(mylogfile); try { library.stuff(); } { restorecurrentthreadlogfile(); } } }
currently i'm using commons-logging own logging well, log4j backend. change that, if needed, or use mix (is that's possible within commons logging framework).
one way write own commons logging implementation (possibly wrapper around log4j), there existing solution?
you want looking @ mapped diagnostic contexts (mdcs). commons logging not support these log4j does, have go directly log4j set up. have roll own filter filter using mdc , apply appenders.
if willing change logging implementations use sl4j logging facade , logback logging implementation. have controller or sort of filter/interceptor add discriminator value key going use discriminate controllers mdc. use siftingappender separate log event separate files.
Comments
Post a Comment