获取最近 500 条记录的消息
我们使用 SLF4J/Logback 组合来执行日志记录。我们的要求之一是,如果出现任何问题,请向支持/开发组发送一封电子邮件,其中包含最近 500 条记录的消息。
我试图浏览文档,但没有找到任何相关内容。
我能想到的方法之一是获取当前日志文件名,读取文件并发送最后 500 条记录。但我不知道如何获取当前的日志文件名。有人知道怎么做吗?或者任何其他更好的选项来检索日志尾部?
谢谢
We are using SLF4J/Logback combination to perform our logging. One of the requirement we have is if anything fails, send an email to support/dev group with last 500 logged messages.
I was trying to go through the documentation, but haven't found anything relevant.
One of the approach, I can think is obtain the current log file name, read the file and send last 500 records. But I dont know how to get the current log file name. anyone knows how to? or any other better option to retrieve the log tail?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来 Log4j 的
SMTPAppender
具有您需要的功能。如果 Logback 缺少类似的附加程序(这会有些令人惊讶),您可以将其源代码视为模型来指导您自己的实现。本质上,这个电子邮件附加程序有一个日志事件的环形缓冲区。当触发事件发生时(默认情况下,发生错误级别或更严重的事件),缓冲区将刷新到电子邮件并发送。
It sounds like Log4j's
SMTPAppender
has the features you require. You could look at its source code as model to guide your own implementation if Logback lacks a similar appender (which would be somewhat surprising).Essentially, this email appender has a ring buffer of log events. When a triggering event occurs (by default, an event at ERROR level or worse), the buffer is flushed to an email and sent.
创建一个自定义 Appender 来缓存最后 500 条日志消息。您可以扩展 SMTPAppender 来发送电子邮件通过从此缓存中读取内容。
从此处开始
Create a custom Appender that would cache the last 500 log messages. You may extend the SMTPAppender to shoot the email by reading the contents from this cache.
start here