我正在使用 Log4j2,一些 beta-10 版本左右。
发生异常时很容易记录堆栈跟踪:
} catch (Exception ex) {
log.error("Doing stuff went wrong", ex);
}
假设虽然没有可用的 Throwable
对象 - 我只是意识到有问题并想记录错误:
if (stuffIsWrong()) {
log.error("Stuff went wrong");
}
我如何告诉 Log4j2 记录从当前方法开始的堆栈跟踪?
最佳答案
只需创建一个新的异常
if (stuffIsWrong()) {
log.error("Stuff went wrong", new Exception("Stracktracegenerator"));
}
关于java - Log4j2:日志堆栈跟踪没有异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23338014/