[slf4j-user] A problem with the lacking "exception" interface

Matt Quigley euroquigs at gmail.com
Wed Jul 16 21:31:07 CEST 2008


I just wanted to suggest something, given that I have a problem with
the given interface. To log an exception with SLF4J, we have:

 public void debug(String msg, Throwable t);

There is no "debug(Throwable t);" for reasons given at
http://www.slf4j.org/faq.html#exception_message. However, what is
given is a series of arguments telling me I don't know what I'm doing.

I completely agree that a message should be given with exceptions,
what I disagree with is that you have to pass in a String to do so.
Not all exceptions are NullPointerExceptions, mind you. There is
absolutely no reason I should have to pass a message to the logger
with the following:

try {
   ...
   throw new MyCustomException("Table not found in the database", tableName);
} catch (MyCustomException e) {
   log.warn("Table not found in the database", e);
}

Given that there is enough information in the exception to log an
error appropriately, why is it that the interface forces me to do it
the "good way (TM)"?  I mean, does adding that extra interface method
really screw things up?  Will it slow things down?  Will it make users
code clunky?  Is it SLF4J's way of making sure everyone is a good
programmer? (I have a feeling that's the answer) One thing it
certainly does is clutter up certain parts of my code unnecessarily.
I can think of a few more reasons why I disagree with this.  Shouldn't
the library be usable in all scenarios?  It's removing functionality
that is already inherently in the library anyways!  The arguments say
that removing this functionality is a good thing (TM), but I couldn't
disagree more.

I just thought that since you guys put a lot of thought into the
interface, I'd tell you how it's affected me in my experiences of
converting many of my company's projects from log4j to SLF4J.  BTW, I
like SLF4J a lot better!

-Matt



More information about the slf4j-user mailing list