简体   繁体   中英

How to log the full stacktrace?

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?

尝试:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM