简体   繁体   English

使用slf4j / logback访问历史日志消息

[英]Accessing Historical Log Messages with slf4j/logback

I have a Swing-based application that logs all messages to text files through slf4j with logback underneath. 我有一个基于Swing的应用程序,该应用程序通过slf4j将所有消息记录到文本文件中,并在下面进行logback。

I'd like to add a feature to show all messages at a certain level(eg fatal) logged in the current session on demand, say in a JTable . 我想添加一个功能,以按需显示在当前会话中记录的特定级别(例如致命)的所有消息,例如在JTable

Does slf4j provide API that lets you access historical log messages, preferably filtered by level or time? slf4j是否提供可让您访问历史日志消息(最好按级别或时间过滤)的API?

Try to use Logback , there is a ch.qos.logback.classic.db.DBAppender class that you can use as an Appender to your fatal errors. 尝试使用Logback ,有一个ch.qos.logback.classic.db.DBAppender类可以用作致命错误的追加者。 You can define your own data structure, just provide the SQL Insert statement. 您可以定义自己的数据结构,只需提供SQL Insert语句即可。 Also, other variants of this DBAppender are provided, so you can choose when do you want to customize the behavior. 另外,还提供了此DBAppender其他变体,因此您可以选择何时自定义行为。

The next thing is that you tie your appender to those loggers that you want to log. 接下来的事情是将附加器绑定到要记录的记录器。

Finally you can manage your logged data within your application (filter, purge/archive) just like your application business data. 最后,您可以像处理应用程序业务数据一样在应用程序(过滤器,清除/归档)中管理记录的数据。

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

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