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

Joern Huxhorn jhuxhorn at bpinteractive.com
Sun Jan 27 17:06:16 CET 2008


Hi Ceki.

I just submitted a solution proposal incl. patch for the described 
shortcoming of slf4j.
Please have a look at http://bugzilla.slf4j.org/show_bug.cgi?id=70
It should not introduce any problems or unexpected behavior and the 1.5 
version bump would be the ideal time to introduce this change.

I hope you like it,
Joern.

Ceki Gulcu wrote:
> 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
>>     
>
>
>   





More information about the slf4j-user mailing list