Actually passing an object with an expensive toString() *IS* the problem.
log4j is NOT the problem in any of these cases. As you stated, log4j won't
bother logging DEBUG if we're set to INFO. But the expensive toString() will
still get evaluated before the call to log.debug() is made.

Technically, I think Jeff is right. A call to:

  log.debug(myObject);

won't have it's toString() called, it just uses the object as the parameter. The logger will first check to see if it's a valid debugging level and punch out if it's not. If it passes that check, it will later call the object's toString to actually find something to log. So the (in this case) implicit call to toString isn't called.

An expensive toString is however an issue for:

  log.debug("Some stuff" + myObject);

Since the concatentation will occur to create the parameter to the debug method, which is what I suspect is happening in a very large percentage of the log statements we have. In this case, the isDebug() check would save us the penalty.



--
Jason Dobies
RHN Satellite / Spacewalk
RHCE# 805008743336126
Freenode: jdob @ #spacewalk #spacewalk-devel

_______________________________________________
Spacewalk-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to