5

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?

1

1 Answer 1

10

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)

1
  • 2
    Yes, this is the correct way. I've done the same thing. I created an appender that formats the messages and stores them in a circular buffer. The the UI can get the circula buffer, via a singleton, and display the log lines. But why format to a text line, better to display as a grid. Commented Jun 18, 2013 at 20:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.