问题
I need to append log4j content to a Swing component (JTextArea or similar). Is there a common way to do this?
回答1:
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.
回答2:
Thanks to Google, I've obviously discovered the Log4j-Swing-Appender.
回答3:
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);
来源:https://stackoverflow.com/questions/1358926/log4j-swing-appender