Tom Tucker
Tom Tucker

Reputation: 11896

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?

Upvotes: 5

Views: 6004

Answers (1)

Guillaume Darmont
Guillaume Darmont

Reputation: 5018

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)

Upvotes: 10

Related Questions