It's only necessary to guard logging statements like that when some additional 
processing is required before the logging method is called. For example:

logger.info("Some info statement");

That's always efficient. But:

logger.info("Some info {} statement {}", request.getHeader("header1"), 
request.getHeader("header2"));

That would be very inefficient when info is disabled. So the first statement 
never needs to be guarded. But the second statement should be:

if (logger.isInfoEnabled()) {
    logger.info("Some info {} statement {}", request.getHeader("header1"), 
request.getHeader("header2"));
}

Anyway, I don't like taking "Enabled" off of the method name. What does this 
mean?

if (logger.isInfo()) { }
if (logger.isDebug()) { }

The logger is an info logger? The logger is a debug logger? Can it be both at 
the same time? It just doesn't make sense to me. isInfoEnabled = much better 
than isInfo.

Nick

On Jan 27, 2014, at 8:06 PM, Matt Sicker wrote:

> I like the shorter version better. Is it always absolutely necessary to guard 
> logging statements like that, though? Or only to save on the unnecessary 
> processing when that level is disabled?
> 
> 
> On 27 January 2014 19:47, Gary Gregory <garydgreg...@gmail.com> wrote:
> Hi All,
> 
> I think I brought this up a long time ago but I thought I'd give it a refresh 
> since we have a lot more voices participating in conversations. Yes, I am 
> aware of making source compatibility simple for porting from version 1 but 
> this is a naming issue that's always displeased me.
> 
> I find the Logger#isLevelEnabled() method names unnecessarily verbose: 
> isDebugEnabled(), isTraceEnabled() and so on. 
> 
> Any likes to rename those simply to isDebug(), isTrace() and so on?
> 
> I find this much more palatable:
> 
> if (logger.isDebug()) {
>    logger.debug(...);
> }
> 
> vs.
> 
> if (logger.isDebugEnabled()) {
>    logger.debug(...);
> }
> 
> ?
> 
> Gary
> 
> -- 
> E-Mail: garydgreg...@gmail.com | ggreg...@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
> 
> 
> 
> -- 
> Matt Sicker <boa...@gmail.com>

Reply via email to