Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / log / JalviewAppender.java
similarity index 56%
rename from src/jalview/gui/JalviewAppender.java
rename to src/jalview/log/JalviewAppender.java
index 1d7064b..07239f8 100644 (file)
  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
  * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
-package jalview.gui;
+package jalview.log;
+
+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.Level;
+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.config.Property;
+
+import jalview.log.JLoggerI.LogLevel;
+import jalview.util.Log4j;
 
 /**
  * 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
 {
+  public final static String NAME = "JalviewAppender";
+
+  public JalviewAppender()
+  {
+    this(LogLevel.INFO);
+  }
+
+  public JalviewAppender(LogLevel loglevel)
+  {
+    super(NAME,
+            Log4j.getThresholdFilter(loglevel == null ? Level.INFO
+                    : Log4j.log4jLevel(loglevel)),
+            Log4j.getSimpleLayout(), false, new Property[0]);
+  }
+
+  protected JalviewAppender(String name, Filter filter,
+          Layout<? extends Serializable> layout, boolean ignoreExceptions,
+          Property[] properties)
+  {
+    super(name, filter, layout, ignoreExceptions, properties);
+    // TODO Auto-generated constructor stub
+  }
 
   static private JTextArea jTextArea = null;
 
@@ -44,9 +76,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(
+            this.getLayout().toByteArray(logEvent), StandardCharsets.UTF_8);
 
     // Append formatted message to textarea using the Swing Thread.
     SwingUtilities.invokeLater(new Runnable()