简体   繁体   English

拦截日志消息slf4j

[英]Intercept Log Messages slf4j

I have an application which uses slf4j as the logging facade. 我有一个使用slf4j作为日志记录的应用程序。 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? 是否有可能为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? 我仔细查看了文档,看到我们可以在实现中更改Appender(比如log4j)来实现这一点,但是我们可以在门面层面自己做吗? The intercept does basic stuff like incrementing a global counter for the number of error messages etc. 拦截执行基本操作,例如递增错误消息数量的全局计数器等。

There is nothing for doing this in the SLF4J API. 在SLF4J API中没有任何操作。

But if your logger is Logback you can do it using a Filter like TurboFilter . 但是如果您的记录器是Logback,您可以使用像TurboFilter这样的过滤器来 TurboFilter

If you're not using Logback you'll probably need something like an AspectJ interceptor. 如果你没有使用Logback,你可能需要像AspectJ拦截器这样的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM