3 import javax.swing.JTextArea;
4 import javax.swing.SwingUtilities;
6 import org.apache.log4j.WriterAppender;
7 import org.apache.log4j.spi.LoggingEvent;
10 * From http://textareaappender.zcage.com/
11 * the means to capture the logs, too.
12 * Simple example of creating a Log4j appender that will
13 * write to a JTextArea.
15 public class JalviewAppender extends WriterAppender {
17 static private JTextArea jTextArea = null;
19 /** Set the target JTextArea for the logging information to appear. */
20 static public void setTextArea(JTextArea jTextArea) {
21 JalviewAppender.jTextArea = jTextArea;
24 * Format and then append the loggingEvent to the stored
27 public void append(LoggingEvent loggingEvent) {
28 final String message = this.layout.format(loggingEvent);
30 // Append formatted message to textarea using the Swing Thread.
31 SwingUtilities.invokeLater(new Runnable() {
33 if (jTextArea!=null) {
34 jTextArea.append(message);