Wednesday, February 16, 2011

log4j notes

Do not use e.printStackTrace

e.printStackTrace prints to the console. You will only see this messages, if you have defined a console appender. If you use Tomcat or other application server with a service wrapper and define a console appender, you will blow up your wrapper.log.
try {
     ......... snip .......
 } catch ( SomeException e) {
     e.printStackTrace();
 }
You can use log.error(e,e). The second parameter passed an exception and will print the stack trace into the logfile.
try {
     ......... snip .......
 } catch (SomeException e) {
     log.error("Exception Message", e);
   // display error message to customer
 }

No comments:

Post a Comment