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: analysis of java application logs Date: Tue, 24 May 2011 14:35:47 -0400 Organization: albasani.net Lines: 60 Message-ID: References: <240520111100099912%jimsgibson@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net oyM1zvJFakvfrhesixBW8c/AIoT/BEMO1U8g+EtADomz17HhEWqYnd93KzvEZRExTnG323vTZtvOzXHkvWtI3noe2Khx8CwhCXy2t7itj12aU3wdy8FU8WjDwU/3dRPV NNTP-Posting-Date: Tue, 24 May 2011 18:35:23 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="7qbS8W+rt6j45vYlfsTNk0Vye1pGAV1tlpKoxFy3Lg5eEj5+Z5inhGH7m6u4Fynd8AFvBkBDHO4YrCmaquKTxZUeO7qW7sDWuiY6TEQVNaWbdpFxIQXJBviF/lfR9eIS"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 In-Reply-To: <240520111100099912%jimsgibson@gmail.com> Cancel-Lock: sha1:gHqOYM9Rt/zd5sAuLrX+8PMVqpk= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4545 On 05/24/2011 02:00 PM, Jim Gibson wrote: > In article, Lew > wrote: > >> Martin Gregorie wrote: >>> Lew wrote: >>>> Martin Gregorie wrote: >>>>> Fair point. However, my usual debugging statement takes the form: >>>>> >>>>> if (debug> 0) >>>>> debugger.trace(result + " = method(" + arg + ")"); >>>>> >>>>> Ugly, I know, but quite efficient, since when debugging is off even the >>>>> cost of the method call cost is. I use an integer to control debugging >>>>> rather than a boolean so I can control its volume: "java Application >>>>> -dd" would be expected to provide more detailed debugging output than >>>>> "java Application -d" >> >>>> What's wrong with >>>> >>>> if ( logger.isDebugEnabled() ) ... >>>> >>>> or >>>> >>>> if ( logger.getLevel().isGreaterOrEqual( Logger.DEBUG )) ... >>>> ? >> >>> Not a lot, though that does involve method call overheads that you may >>> not want in a tight loop. >> >> Seems like it's a simple equality test that would be HotSpotted away. > > My understanding of the log4j and java.util.Logger classes is that each > logger exists within a hierarchy of classes, and that to determine > whether or not a specific logger call will produce output, the library > must test each level, starting at the specific class and traversing > upwards in the hierarchy. > > So using a static variable as below to enable and disable logging > output can save some execution time: > > static final boolean debug = false; > > if( debug ) { > logger.debug(...); > } > > Whether or not that is significant, depends upon the situation, of > course. All this theory indicates what to measure in any real situation, but to echo your "of course", you won't know what to conclude prior to that measurement. Now why you'd *ever* want to put a log statement inside a tight, performance-critical loop in the first place is a whole 'nother question. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg