How to log exception and message with placeholders with SLF4J

匆匆过客 提交于 2021-01-20 14:42:27

问题


What's the correct approach to log both an error message and an exception using SLF4J?

I've tried doing this but the exception stack trace is never printed:

logger.error("Unable to parse data {}", inputMessage, e);

In this case I want to populate {} with the inputMessage as well as logging out the exception stacktrace.

The only way I can see to do this would be to do this:

logger.error("Unable to parse data " + inputMessage, e);

which is not pretty.


回答1:


As of SLF4J version 1.6, SLF4J will interpret the last parameter as you intended, i.e. as an exception. You must be using an older version of SLF4J API.



来源:https://stackoverflow.com/questions/5951209/how-to-log-exception-and-message-with-placeholders-with-slf4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!