tags:

views:

625

answers:

3

I need to append log4j content to a Swing component (JTextArea or similar). Is there a common way to do this?

+4  A: 

Thanks to Google, I've obviously discovered the Log4j-Swing-Appender.

Nate
+3  A: 

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.

Nate
+1  A: 

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); 
orcus