简体   繁体   中英

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.

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 .

Does slf4j provide API that lets you access historical log messages, preferably filtered by level or time?

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. You can define your own data structure, just provide the SQL Insert statement. Also, other variants of this DBAppender are provided, so you can choose when do you want to customize the behavior.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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