Reputation: 19442
I need to append log4j content to a Swing component (JTextArea or similar). Is there a common way to do this?
Upvotes: 15
Views: 8229
Reputation: 19442
Instead of introducing an external library, I ended up editing the log4j.properties file to include the following:
log4j.rootCategory=DEBUG, app
log4j.appender.app=path.to.class.extending.WriterAppender
Then I employed an observer pattern to post the data into my GUI's JTextArea.
Upvotes: 12
Reputation: 41
to make the JScrollPane wrapping the target component (e.g. JTextArea) automatically scroll down to show the latest log entries, consider calling:
org.apache.log4j.lf5.viewer.LF5SwingUtils.makeVerticalScrollBarTrack(scrollPane);
Upvotes: 4
Reputation: 19442
Thanks to Google, I've obviously discovered the Log4j-Swing-Appender.
Upvotes: 7