拦截日志消息slf4j [英] Intercept Log Messages slf4j

查看:816
本文介绍了拦截日志消息slf4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用slf4j作为日志外观的应用程序.现在,我想在将传输传递给基础日志系统之前拦截所有错误消息. slf4j可以这样做吗?我仔细阅读了文档,发现可以在实现中更改Appenders(例如log4j)来实现这一目标,但是我们可以在外观级别本身上做到这一点吗?拦截程序执行一些基本操作,例如为错误消息的数量增加一个全局计数器等.

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.

推荐答案

在SLF4J API中没有执行此操作的

There is nothing for doing this in the SLF4J API.

但是,如果您的记录器是Logback,则可以使用过滤器来实现,例如.

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

如果您不使用Logback,则可能需要使用AspectJ拦截器之类的东西.

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

这篇关于拦截日志消息slf4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆