Java: Log Exception Correctly with Log4j
By admin on Aug 18, 2008 in Java, Programming
This is simple but often overlooked.
There are numerous code like this
1: try {
2: ….
3: }
4: catch (Exception e) {
5: e.printStackTrace();
6: }
printStatckTrace prints out to “stderr”. If you are using log4j and you should do this
1: try {
2: …
3: }
4: catch (Exception e) {
5: log.error(“Exception details “, e);
6: }
For every debug, info, warn, error and fatal methods there is a corresponding method that accepts a Throwable as the second parameter.
Post a Comment