On Thu, 22 Apr 2004, Robert Pepersack wrote: | You could create a class boolean variable that is set once by | isDebugEnabled(). Then you could say: | | private boolean debug = logger.isDebugEnabled(); | | In you method code you could say: | | if (debug) cat.debug(myObject.showState()); | | This would make it so that you only call isDebugEnabled() once in each class.
.. and so that you couldn't "live reconfigure" your log-configuration - a MAJOR loss. | | | At 11:54 AM 04/22/2004 -0400, you wrote: | >This is a little off from the original question, and note that we also | >haven't touched any of our logging code in quite a while, but: | > | >We found that we had to address some performance problems where there was | >an insignificant cost to creating the string that we were going to send to | >log4j. | > | >For example, you might have: | > | > cat.debug(myObject.showState()); | > | >or some such thing, and the issue is that even if debug logging is | >disabled, the call into cat.debug() is still made, which means the call to | >myObject.showState() is also made, even if the results from showState() | >are in fact never used. | > | >We handled this by wrapping all of logging statements (well, at least | >debug ones, I think) in a conditional, like this: | > | > if (cat.isDebugEnabled()) cat.debug(myObject.showState()); | > | >to avoid that overhead. | > | >I was never really happy with this. I suppose some sort of helper object | >might have made more sense... or is there a better way now to deal with this? No, there really aren't any easier (although there is some trick with some anonymous class-whatever thingy that is almost as good, and takes 5 times as much writing) - but it shouldn't be that difficult. See, the problem is your programming language - or maybe rather how nice that language is - it doesn't evaluate things it doesn't need to - and that's what you're exploiting in that debug-statement. Most IDE's have "code templates". I have these two in my CodeGuide: logd : if (log.isDebugEnabled()) log.debug("|"); logi : if (log.isInfoEnabled()) log.info("|"); then I just write "logd"+ctrl+j, and then the code template is inserted over the "logd" letters, and the cursor is placed at the pipe-character - even easier than writing log.debug("<write here");, isn't it? -- Mvh, Endre Stølsvik M[+47 93054050] F[+47 51625182] Developer @ CoreTrek AS - http://www.coretrek.com/ CoreTrek corporate portal / EIP - http://www.corelets.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]