[slf4j-user] logging a stack trace along with a parameterized string

Ceki Gulcu listid at qos.ch
Wed Dec 19 21:30:43 CET 2007


Hi Lowell,

This is a well-known shortcoming of the SLF4J API. However, since exceptions are 
by definition rare, you can write

LOG.debug("Got a "+e.getClass().getName()+" with value "+ e.getValue(), e);

with an *infrequent* loss in performance. Of course, this form is also less 
pleasant to write, but again you write less of these.

HTH,

Lowell Kirsh wrote:
> Looking at the API, I can't figure out how to log an exception's stack 
> trace along with a parameterized string. What I want is something like:
> 
> ...
> catch (FooException e) {
>   LOG.debug("Got a {} with value {}", e.getClass().getName(), 
> e.getValue(), e);
> }
> 
> But it seems from the API that I can either pass a Throwable to the log 
> method, or some arguments to be interpolated into the String. Is there 
> an idiom for doing both?
> 
> Thanks,
> Lowell


-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch



More information about the slf4j-user mailing list