我正在使用Log4j2,一些beta-10版本。
发生异常时,很容易记录堆栈跟踪:
} catch (Exception ex) {
log.error("Doing stuff went wrong", ex);
}
Run Code Online (Sandbox Code Playgroud)
假设虽然没有Throwable可用的对象-我只是意识到有一个问题,想记录一个错误:
if (stuffIsWrong()) {
log.error("Stuff went wrong");
}
Run Code Online (Sandbox Code Playgroud)
如何告诉Log4j2从当前方法开始记录堆栈跟踪?
只需创建一个新的异常
if (stuffIsWrong()) {
log.error("Stuff went wrong", new Exception("Stracktracegenerator"));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3858 次 |
| 最近记录: |