Intercept Log Messages slf4j

☆樱花仙子☆ 提交于 2020-01-02 01:05:16

问题


I have an application which uses slf4j as the logging facade. Now I would like to intercept all the error messages before the transfer is handed out to the underlying logging system. Is it possible to do that for slf4j? I looked through the documentation and see that we can change the Appenders in the implementation (like log4j) to achieve this but can we do this at the facade level itself? The intercept does basic stuff like incrementing a global counter for the number of error messages etc.


回答1:


There is nothing for doing this in the SLF4J API.

But if your logger is Logback you can do it using a Filter like TurboFilter.

If you're not using Logback you'll probably need something like an AspectJ interceptor.



来源:https://stackoverflow.com/questions/13956262/intercept-log-messages-slf4j

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