> On Thursday, October 11, 2001 4:52 AM, Michael Mason wrote:
>
> > On Wednesday, October 10, 2001 7:51 PM, Mark Womack wrote:
> >
> > When logging an exception object, is there anyway to print out the stack
> > trace information? Right now, it seems to only print the exception message.
> > Is there a way to configure the output settings?
>
> If I do
>
> myCategory.error("Caught an exception", e);
>
> if prints the stack trace for me. I haven't done anything special
> when configuring my output settings. I normally actually do this:
>
> myCategory.error("Caught an exception: " + e.getMessage(), e);
I figured this out from the javadoc:
"WARNING Note that passing a Throwable to this method will print the name
of the Throwable but no stack trace. To print a stack trace use the
error(Object, Throwable) form instead."
Links:
http://jakarta.apache.org/log4j/docs/api/org/apache/log4j/Category.html#error(java.lang.Object)
http://jakarta.apache.org/log4j/docs/api/org/apache/log4j/Category.html#debug(java.lang.Object)
My $0.02:
I like this approach, ie making the user clarify how to handle the Throwable
object by choosing which method to invoke. With that being said, I have
to admit that I overrode this behavior in my common superclass, e.g.
public static void debug ( Object src, Object msg ) {
Category category = getCategory( src );
if ( msg instanceof Throwable ) {
category.debug( null, (Throwable)msg );
} else {
category.debug( msg );
}
}
Ken.