Linc Linc - 5 months ago 19
Java Question

How do you write a full stack trace to the log?

I was catching an exception and trying to write the stack trace to the logs like this:

log.warn(e.getMessage());


But all it said was

null


So I changed it to

log.warn(e.toString());


And now it says only

java.lang.NullPointerException


How do I write the full stack trace to the log so I can see where this Exception is being generated in the app?

Answer

Usually:

log.warn("message", e);

But it depends on your logging framework too.

Comments