[slf4j-dev] Why no error(Throwable) on the Logger interface?

Jukka Zitting jukka.zitting at gmail.com
Wed May 27 23:30:41 CEST 2009


Hi,

On Wed, May 27, 2009 at 6:39 PM, Robert Elliot <rob at lidalia.org.uk> wrote:
> 1) Logging in the uncaught exception handler for a thread.

    log.error("Uncaught exception from thread " + thread, exception);

Without the message you'll just see some random exception and you'll
need to dig into the stack trace (if one is available) to find whether
it came from a thread (which thread?) and where it was eventually
caught.

> 2) Logging an exception from a service in a controller.

Why is the controller calling the service? There must be some trigger
for the service call, which is then the context of the exception.

    log.error("Failed to process request " + request + " using service
" + service, exception);

In a properly designed system that context information is not known by
the service, so it can't be included in the exception.

Note that there are many cases (throwaway or test code, etc.) where it
doesn't make sense to invest time in writing such detailed log
messages, but as Joern mentioned you can always use log.error("",
exception) in such cases.

BR,

Jukka Zitting



More information about the slf4j-dev mailing list