Re: Aspect questions?
On 02/26/2012 10:10 AM, markspace wrote:
On 2/26/2012 9:22 AM, Novice wrote:
If so, the next logical step would be to treat all the stuff in the
Common project similarly. If I put all of those classes in package
com.novice.common, then each class would have this:
Logger logger = Logger.getLogger("com.novice.common");
Just as an aside, it's more common to use something like
java.util.logging.Logger.getLogger( getClass().getName() );
instead of a string constant. String constants probably won't be refactored
when a class is renamed or moved to another package. The above needs no
refactoring.
Also:
<http://commons.apache.org/logging/guide.html#Developing%20With%20JCL>
This section points out that it's more efficient to use "static" for the
logger. In desktop apps, that's what I'm used to seeing. However it also says
that "static" interacts poorly with JEE classloaders, so using instance
variables is the norm in JEE (and w/ Tomcat too).
"Efficient"? Really? Sounds like premature optimization, and it's the wrong
criterion down the line for loggers. *How* much more "efficient", and at what
cost, is the 'static' logger?
I prefer instance members for loggers. Greater flexibility and no measurable
loss in "efficiency", whatever that is. Actually, I find instance member
loggers more efficient, for the metric of efficiency that I care about.
(Robustness in the face of refactoring, per your suggestion, which wouldn't
compile if the logger were static.)
Aside: log4j lets you skip the 'getName()' call and just specify the class as
an argument, the name-by-class pattern is so widespread.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg