Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Question about loggers Date: Wed, 07 Mar 2012 15:21:03 -0800 Organization: A noiseless patient Spider Lines: 47 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 7 Mar 2012 23:21:07 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="31211"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/l62FeuNmgYTzk4Cz2G41qF0ysf7PNBaw=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: Cancel-Lock: sha1:L2PsQDYiZbDgF5Fy1gZQe3N9zGI= Xref: csiph.com comp.lang.java.programmer:12754 On 3/7/2012 1:52 PM, Novice wrote: > My impression from the "Aspect Questions" thread was that the "best > practices" approach to logging was to use named loggers, where, in essence, > each method that needs to write to the log creates a named logger via > > Logger logger = Logger.getLogger(getClass().getName()); I could see an app that was divided into functional parts, like maybe "DATABASE" and "GUI", etc. where the logging was specified to use those names: Logger log = Logger.getLogger( "GUI" ); But while I could see this, I've never actually heard of anyone specifying it. Loggers by class name is all I've ever seen. > > Also, Stelting mentions that you can use the LogManager to "cache Logger > objects for repeat use". What circumstances would justify using LogManager? > I was under the impression that simply doing Logger.getLogger() was > perfectly adequate for a professional quality program. Why would LogManager > be any better than simply making the logger a class variable? I think I've done this, exactly once in my life: public class MyLogger extends Logger { ... } ... MyLogger log = new MyLogger(); LogManager.getLogManager().addLogger( log ); If you go through the Logger.getLogger( name ) method this is done for you. If you make your own logger for some reason, you can still use the LogManger to cache it. > Then, I wrote a version using a named logger and a single class variable > and the whole thing looks a lot simpler and cleaner: It's kind of six of one and half dozen of another. Do what makes you happiest. But assume any given shop might have different ideas what is best, and be prepared to adjust.