[slf4j-user] (no subject)

DasUntier at gmx.net DasUntier at gmx.net
Thu Jan 26 09:28:04 CET 2012


Hello,

maybe I'm wrong, but I from the description

http://www.slf4j.org/faq.html#logging_performance

I understand, that the following two statements should be equivalent, considering the current logging level is INFO or higher:

// first
if (logger.isDebugEnabled()) {
logger.debug("Msg: " + someObject);
}

// second
logger.debug("Msg: {}", someObject);

But they aren't, if you want to call a method from the object:

// Object might be null, for some reason in some logging levels
Object o = null;

// Everythings fine
if (logger.isDebugEnabled()) {
logger.debug("Msg: " + o.hashCode());
}

// NullPointerException is thrown, since o is null for DEBUG level
logger.debug("Msg: {}", o.hashCode());

Is this a bug or intended behaviour? I couldn't find any hints in the documentation.

Greetings,

Aaron Kunde
-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de


More information about the slf4j-user mailing list