Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Aspect questions? Date: Sun, 26 Feb 2012 13:47:25 -0800 Organization: albasani.net Lines: 43 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net L0JlOftuguESjGcYhwqS9hPjd267umm9iEhUKnECg7rxqiUaNX89/Ui2FeIed4aQegvDj2EB4Dg4drHo32SoHXVERjgJfND+jRuYJHHkfRYQcK/NbPLbqyhBlXFun5Pt NNTP-Posting-Date: Sun, 26 Feb 2012 21:47:26 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="Mhjb39CmxmiH6WLqGF4UY2m7yTKN2mU0z/lZts9wsu6zxlqomT3M0FbyKAGFB7v8GOe4U4q94GiStEMcrhX7HvGluoJ4HaYH28+VwSqvt1MLwwZa4J04TEM1kwoaPLGE"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: Cancel-Lock: sha1:f6zNW5LTvy2e1+KF6LyEK2pjrrg= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:12386 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: > > > > 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