You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Tim Nguyen <ti...@yahoo.com> on 2008/04/04 21:02:00 UTC
Log Utility
Hi,
I am writing a Log Utility to check the log level first before creating a string object. For example, if my log level is INFO, and I call:
log.debug(new String("test"));
It will still instantiate the String object even thought it doesn't log anything.
So I would like to write an Utility to check the level first, if the log level is lower, then I don't have to instantiate the object and just skip it.
Anybody knows what is the easy way to do that?
Thanks,
____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com
Re: Log Utility
Posted by Robert Pepersack <RP...@mdinsurance.state.md.us>.
Hi Tim,
The Logger class has a way of checking the level first.
First put this in your instance variables:
private static final Logger logger = Logger.getLogger("my.package.MyClass");
private final boolean debug = logger.isDebugEnabled();
Then put this in your method:
if (this.debug)
{
logger.debug(new String("test"));
}
Hope this helps.
Robert Pepersack
Senior Lead Developer
Maryland Insurance Administration
410-468-2054
>>> Tim Nguyen <ti...@yahoo.com> 04/04/2008 3:02 PM >>>
Hi,
I am writing a Log Utility to check the log level first before creating a string object. For example, if my log level is INFO, and I call:
log.debug(new String("test"));
It will still instantiate the String object even thought it doesn't log anything.
So I would like to write an Utility to check the level first, if the log level is lower, then I don't have to instantiate the object and just skip it.
Anybody knows what is the easy way to do that?
Thanks,
____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org