[slf4j-user] Use of message format strings w/ throwables

Chad La Joie chad.lajoie at switch.ch
Wed Jun 24 07:41:09 CEST 2009


The current API does not let you use the message formatting 
functionality  in conjunction with Throwable arguments.  I've seen 
discussion that the reason for this is that if you're dealing with an 
exception the overhead is already so high that the performance benefit 
of using the format string to defer final message constructions is 
meaningless.

However, I'd like to propose that readability might be another reason 
for allowing this.  Take for example this message:

log.error("Some bad thing happened because request with ID '" + id + "' 
from requester '" + requesterId + "' did not meet security requirement 
'" + secPolId + "'", e)

I would argue that the following is much more readable:

log.error("Some bad thing happened because request with ID '{}' from 
requester '{}' did not meet security requirement '{}'", new Object[] 
{id, requesterId, secPolId}, e)

This would require adding a new method for each log level with the 
arguments; format, argArray, throwable.

Does this seem like a reasonable addition to the API strictly from a 
readability aspect within the code using SLF4J?

-- 
SWITCH
Serving Swiss Universities
--------------------------
Chad La Joie, Software Engineer, Net Services
Werdstrasse 2, P.O. Box, 8021 Zürich, Switzerland
phone +41 44 268 15 75, fax +41 44 268 15 68
chad.lajoie at switch.ch, http://www.switch.ch




More information about the slf4j-user mailing list