Logging stack traces with Log4J

The Dining.Name Web application uses Log4J, Apache's logging library for Java, to log the behavior of classes that import XML data into a MySQL database.

Log4J is a simple class library -- the basics take no more than a half-hour to learn, as I described in a Linux Magazine article in 2002. It supports four levels of logging and external configuration. Right now, I'm building Dining.Name at debug level and getting verbose output. When I'm confident that it works, I'll change it to fatal level by tweaking a properties file and only see crash details.

One thing I needed Log4J to do was include a stack trace with fatal exceptions. The printStackTrace() method can't be used because it displays on standard output. As I discovered in a manual on Red Hat's Web application framework, including a stack trace is easy: Log the exception object instead of a string. The exception's message and stack trace will be logged automatically.

Comments

i also have this problem . somebody help me . thanks in advance.

in your log4j config file, the %x will include the stack.



%x did not work for jdbc appender

hi try the solution on this page.

narencoolgeek.blogspot.com

'Logger.error(message, exception)' would print the stack trace to all the registered appenders.

Add a Comment

All comments are moderated before publication. These HTML tags are permitted: <p>, <b>, <i>, <a>, and <blockquote>. This site is protected by reCAPTCHA (for which the Google Privacy Policy and Terms of Service apply).