拦截日志消息slf4j

编程入门 行业动态 更新时间:2024-10-25 09:30:54
本文介绍了拦截日志消息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

本文发布于:2023-11-25 03:58:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628228.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:消息   日志   slf4j

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!