JAL-3949 An attempt at converting to Log4j 2 -- no output achieved!
[jalview.git] / src / jalview / gui / JalviewAppender.java
index 51c76c0..229a1f6 100644 (file)
@@ -1,36 +1,66 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
  *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
- * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
  * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.gui;
 
+import java.io.Serializable;
+import java.nio.charset.StandardCharsets;
+
 import javax.swing.JTextArea;
 import javax.swing.SwingUtilities;
 
-import org.apache.log4j.WriterAppender;
-import org.apache.log4j.spi.LoggingEvent;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.layout.PatternLayout;
 
 /**
  * From http://textareaappender.zcage.com/ the means to capture the logs, too.
  * Simple example of creating a Log4j appender that will write to a JTextArea.
  */
-public class JalviewAppender extends WriterAppender
+public class JalviewAppender extends AbstractAppender
 {
 
+  private final static Layout simpleLayout;
+
+  static
+  {
+    // SimpleLayout pattern found from
+    // https://logging.apache.org/log4j/log4j-2.12.4/manual/migration.html
+    simpleLayout = PatternLayout.newBuilder().withPattern("%level - %m%n")
+            .build();
+  }
+
+  protected JalviewAppender()
+  {
+    this("JalviewAppender", null, simpleLayout);
+  }
+
+  protected JalviewAppender(String name, Filter filter,
+          Layout<? extends Serializable> layout)
+  {
+    super(name, filter, layout);
+    // TODO Auto-generated constructor stub
+  }
+
   static private JTextArea jTextArea = null;
 
   /** Set the target JTextArea for the logging information to appear. */
@@ -42,9 +72,10 @@ public class JalviewAppender extends WriterAppender
   /**
    * Format and then append the loggingEvent to the stored JTextArea.
    */
-  public void append(LoggingEvent loggingEvent)
+  public void append(LogEvent logEvent)
   {
-    final String message = this.layout.format(loggingEvent);
+    final String message = new String(simpleLayout.toByteArray(logEvent),
+            StandardCharsets.UTF_8);
 
     // Append formatted message to textarea using the Swing Thread.
     SwingUtilities.invokeLater(new Runnable()