Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listening for Log Messages in slf4j/logback

I have a Swing-based application without a console that logs all messages to text files through slf4j with logback underneath.

Whenever a message is logged, I'd also like to add it to a JTextArea for the end user to see on the screen.

These messages should be formatted the sameway as the log files for consistency.

Does slf4j/logback have API that lets you add a listener for log messages so that I can copy them to JTextArea?

like image 452
Tom Tucker Avatar asked Jan 13 '23 03:01

Tom Tucker


1 Answers

Logback Appenders are listeners for log messages. Just implement a custom appender that will log in a JTextArea.

You can then create, configure and add appenders to loggers programmatically, or using an external config file (logback.xml)

like image 61
Guillaume Darmont Avatar answered Jan 22 '23 11:01

Guillaume Darmont