Reputation: 7267
Out of curiosity, is there any benefit when logging (using log4j) to use the above approach:
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("New Session Created");
}
rather than just:
LOGGER.debug("New Session Created");
Is it merely a (potential) performance enhancement and would it still be relevant? Should this be used to wrap ALL debug output?
Thanks for your thoughts!
Upvotes: 0
Views: 78
Reputation: 5751
In your use case, no, there's no benefit whatsoever.
However, if you are constructing a new string, for example, "New Session Create" + SessionID, then you'd want to avoid the string construction and rather use the boolean check.
It's a small difference, but in a large application, this string construction, and the associated garbage collection, could become a point of performance impact. If you pass static strings, however, you are actually creating a duplicate check, which, while also small, has possible performance impact.
Upvotes: 1