Fergus,
Help me understand more of what you are doing ? How/Where do you get the handler to
the logger (Logger.getLogger(....)) to be able to control the level at run time. Do
you call your own debug method from inside your code ?
Thks,
- Ashish.
Fergus Gallagher <[EMAIL PROTECTED]> wrote:Yes, this a hard one.
One option we've used is to wrap MessageFormat
debug("Hello {1}", obj)
with cases for 1..n args and a catch-all
debug("Hello {1}.....", new Object[] {a,b,.....});
with
void debug(String fmt, Object arg) {
if (LOG.isDebugEnabled()) {
LOG.debug(MessageFormat.format(fmt, new Object[] {arg});
}
}
etc.
However, this doesn't cope with "expensive" method calls:
debug("", obj.someSlowMethod());
In this case it's probably best to wrap with isDebugEnabled() yourself. A
(messy) alternative is to use introspection:
debug(fmt, obj, "someSlowMethod");
so that obj.someSlowMethod is only evaluated if really required. Yuck.
On Tue, Feb 11, 2003 at 12:33:07PM -0500, John Guthrie wrote:
> i think the rule is not to check *every time*, but only if the statement you
> are sending to the debugger is expensive to create. our rule of thumb is to
> check if the message requires more than one string concatenation. so for
> this:
> logger.debug("look out!");
> or this:
> logger.debug("look "+"out!");
> there is no need to check. but beyond that, you should, because otherwise
> you could be wasting time creating messages that don't get logged.
>
> john
>
> ----- Original Message -----
> From: "Ashish Jain"
> To:
> Sent: Tuesday, February 11, 2003 12:26 PM
> Subject: IsDebugEnabled
>
>
> >
> > All,
> >
> > I am looking at the log4j documentation and it states the following
> >
> > "To avoid the parameter construction cost write:
> >
> > if(logger.isDebugEnabled() {
> > logger.debug("Entry number: " + i + " is " +
> > String.valueOf(entry[i]));
> > }"
> >
> > I do want to avoid the parameter construction cost, but I don't want to
> > check for IsXXXEnabled everytime I use a log statement because it makes
> > my code clumsy. Is there a better way of doing this ? Is there a config
> > flag somewhere ? or should I extend the logger classes and check for
> > IsXXXenabled before calling the Log4j classes. And then my code can call
> > my log4jextended classes. Again, I don't want to check for IsXXXEnabled
> > every time I use a log statement.
> >
> > Any help is appreciated.
> >
> > Thks,
> >
> > - Ashish.
> >
> >
> >
> > ---------------------------------
> > Do you Yahoo!?
> > Yahoo! Shopping - Send Flowers for Valentine's Day
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
--
Fergus Gallagher Tel: +44 (20) 8742 1600
Orbis Fax: +44 (20) 8742 2649
414 Chiswick High Street email: [EMAIL PROTECTED]
London W4 5TL Web: http://www.orbisuk.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day