logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bender Heri" <HBen...@Ergonomics.ch>
Subject RE: [SPAM (Bayesain Analysis)] - Best practice on declaring Loggers - Bayesian Filter detected spam
Date Tue, 13 Jun 2006 11:52:49 GMT
If you use log4j without any extras it's good practice to declare the logger as 

    private static final Logger myLog = Logger.getLogger( MyClass.class );

private: because every descendant in class hierarchie can have its own logger instance (i.e.
for fintuning the log levels)
static: because the logger is loaded only once (when loading the class the first time)
final: because the logger reference does not change during the runtime of the app

If you use a own repository selector in order to separate some logger universes (LogManager
and it's default RepositorySelector is a singleton per classloader) then you have to consider

- if the class is only used in one Logger universe you can declare it like above
- if the class is used in different Logger universes, but a instance of the class is used
only in one, you omit the "static"
- if a class instance is used in different Logger universes, or a util class with static methods,
you have to get the logger instance locally in every method.


> -----Original Message-----
> From: Konstantinos Karadamoglou [mailto:kkarad@googlemail.com]
> Sent: Tuesday, June 13, 2006 12:27 PM
> To: log4j-user@logging.apache.org
> Subject: [SPAM (Bayesain Analysis)] - Best practice on 
> declaring Loggers
> - Bayesian Filter detected spam
> Hello all,
> Which is the best practice of declaring Loggers? For 
> instance, should they
> be static, private, final? and why?
> Thank you in advance, Kostas

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message