March 23, 2005

Exception logging with log4j

When trying to diagnose a problem with some software earlier today, I discovered this little annoyance.
try {
do some stuff
} catch(Exception ex) {
logger.error(ex);
}

This will only log a brief message and not the whole stacktrace (at least in my case of an NPE, giving you no information as to where the exception was occuring.

However…

try {
do some stuff
} catch(Exception ex) {
logger.error("Failed to do some stuff",ex);
}
This will dump out the whole stack trace. How odd.

- 2 comments by 1 or more people Not publicly viewable

  1. clark

    Well, that's by design.

    Take a look at the api. When you just call logger.error(e), it treats it like a generic Object, and the best that it can do is call toString on it.

    But, when you call logger.error(String s, Exeption e), it knows that you've passed it a throwable and it handles it like one.

    20 Oct 2005, 19:58

  2. Yeah, I see your point, but it is still annoying :)

    21 Oct 2005, 15:40


Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

March 2005

Mo Tu We Th Fr Sa Su
Feb |  Today  | Apr
   1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31         

Tags

Search this blog

Most recent comments

  • One thing that was glossed over is that if you use Spring, there is a filter you can put in your XML… by Mathew Mannion on this entry
  • You are my hero. by Mathew Mannion on this entry
  • And may all your chickens come home to roost – in a nice fluffy organic, non–supermarket farmed kind… by Julie Moreton on this entry
  • Good luck I hope that you enjoy the new job! by on this entry
  • Good luck Kieran. :) by on this entry

Galleries

Not signed in
Sign in

Powered by BlogBuilder
© MMXXII