logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Hache <cha...@tsco.ca>
Subject Filter log based on package when using getLogger(String)
Date Wed, 18 Jul 2012 17:26:11 GMT
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-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message