使用 JMS 和 logback 进行分布式日志记录
我正在开发一个项目,将多台机器的日志数据合并到一个数据库中。
我必须记录场景:
- 通常的异常记录和开发人员日志记录,例如开发人员将级别转变为调试。
- “审核”日志记录。特殊场景需要记录在具有单独结构的单独数据库中。
我正在使用 logback 和 JMS。 “客户端”记录到 JMS 队列,“服务器”读取队列并写入数据库。
我正在寻找一种简单的方法来区分这两种类型的日志。 我想做的是创建另一个日志级别,例如“审核”,然后我可以在“服务器”端检查它并创建我们的特殊对象结构并写入我们单独的数据库。
然而,这在 logback 中是不可能的。我已经考虑过标记,但这意味着开发人员必须显式应用标记。我的另一个选择是拥有两个独立的记录器,让开发人员获取正确的记录器。这并不像我想要的那么优雅。
我希望开发人员只执行 log.debug 进行调试,log.error 执行错误,log.audit 执行审计。
任何建议,有人必须解决类似的问题吗?
I'm working on a project to combine log data from multiple machines to a single DB.
I have to logging scenarios:
- usual logging of exceptions and developer logging e.g. a dev turns the level to debug.
- "Audit" logging. Special scenarios need to be logged in a separate DB with separate structure.
I'm using logback and JMS. "Client" logs to JMS Queue and "Server" reads form queue and writes to DB.
I'm looking for a simple way to distinguish the two types of logs.
What I would like to do is create another log level, e.g. "audit" which I could then check on the "server" side and create our special object structure and write to our separate DB.
However this is not possible in logback. I have considered markers but that means a dev has to explicitly apply a marker. My other option is to have two separate loggers and for the dev to grab the correct logger. That's not quite as elegent as I would like.
I'd like the dev to just do log.debug for debug, log.error for errors and log.audit for audit.
Any advice, any one had to solve a similar issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,为什么不直接使用 DBAppender并直接登录数据库,跳过JMS层?如果您关心性能,Logback 提供异步日志的工具。
至于过滤,单独的记录器是最简单、最干净的方法(然后简单地按记录器/类别过滤)。这种方法强调了这样一个事实:这些是特殊日志,而不是普通的应用程序调试。我什至会考虑将此审计日志记录包装在某些服务/方面中,以将其与业务逻辑分开。
如果你确实想重用现有的记录器,你可以使用 Logback filters 来调度和过滤事件在运行时。
First of all, why not just use DBAppender and log directly to the database, skipping JMS layer? Logback provides facilities to log asynchronously if performance is your concern.
As for filtering, separate logger is the easiest and cleanest way to do this (and then simply filter by logger/category). This approaches emphasizes the fact that these are special logs, not the ordinary application debug. I would even consider wrapping this audit logging in some service/aspect to separate it from business logic.
If you really want to reuse existing loggers, You can use Logback filters to dispatch and filter events at runtime.