I'm using log4j
to log unhandled exceptions. But how can I log the stacktrace?
I tried the following:
Logger.getRootLogger().fatal(e);
Result:
2013-11-05 14:25:07,078 FATAL root: java.lang.NullPointerException
BUT no stacktrace! Why?
I'm using log4j
to log unhandled exceptions. But how can I log the stacktrace?
I tried the following:
Logger.getRootLogger().fatal(e);
Result:
2013-11-05 14:25:07,078 FATAL root: java.lang.NullPointerException
BUT no stacktrace! Why?
Try with:
Logger.getRootLogger().fatal(e, e);
field element
private static final Logger LOGGER = LogFactory.getLogger(YourClazz.class);
in your methods, simply log e
LOGGER.error("There was an error {}",e);
and it will print the full stacktrace