Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我log4j用来记录未处理的异常。但是如何记录堆栈跟踪?
log4j
我尝试了以下方法:
Logger.getRootLogger().fatal(e);
结果: 2013-11-05 14:25:07,078 FATAL root: java.lang.NullPointerException 但没有堆栈跟踪!为什么?
2013-11-05 14:25:07,078 FATAL root: java.lang.NullPointerException
尝试:
Logger.getRootLogger().fatal(e, e);
字段元素
private static final Logger LOGGER = LogFactory.getLogger(YourClazz.class);
在您的方法中,只需登录 e
LOGGER.error("There was an error {}",e);
它将打印完整的堆栈跟踪