Use MDC for the string? ■ DOUGLAS E. WEGSCHEID // LEAD ENGINEER (269) 923-5278 // douglas_e_wegsch...@whirlpool.com "A wrong note played hesitatingly is a wrong note. A wrong note played with conviction is interpretation."
Charles Hache <cha...@tsco.ca> 07/18/2012 01:26 PM Please respond to "Log4J Users List" <log4j-user@logging.apache.org> To log4j-user@logging.apache.org cc Subject Filter log based on package when using getLogger(String) Hello folks, Most of my loggers are constructed with the Logger.getLogger(String) function, so that I can have loggers like "Device(#3, Some Description)" instead of "ca.something.package.Device" with the goal of being able to more easily identify which instances are writing what log lines. I've found that when I do this I can't use properties to filter the log level, such as log4j.logger.ca.something.package=INFO I figure this is because if I use getLogger(Device.class) it gets the package of the logger from the class I give it and it all works from there. So this all makes sense, but brings up two questions: Can I still declare my loggers with a String name (getLogger(String)) and somehow still use package-style log level selection in the properties file? If not, do you guys have any tips on how to differentiate between instances when they're logging? The obvious solution would be to prepend any log message I want to write with a description of the instance, but that seems like a lot of extra work. I think really what I'm looking for is something like getLogger(Class theClass, String theName), but maybe there is an already-implemented way to do this. Any tips? Regards, Charles --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org