Merge branch 'improvement/JAL-4409_implement_extra_schemes_in_getdown' into develop
[jalview.git] / src / jalview / util / ErrorLog.java
diff --git a/src/jalview/util/ErrorLog.java b/src/jalview/util/ErrorLog.java
new file mode 100644 (file)
index 0000000..e94b59e
--- /dev/null
@@ -0,0 +1,58 @@
+package jalview.util;
+
+public class ErrorLog
+{
+  private static boolean hasConsole = true;
+
+  public static void outPrintln(String message)
+  {
+    println(message, false);
+  }
+
+  public static void errPrintln(String message)
+  {
+    println(message, true);
+  }
+
+  public static void println(String message, boolean err)
+  {
+    if (hasConsole)
+    {
+      try
+      {
+        hasConsole = jalview.bin.Console.initLogger();
+        if (hasConsole)
+        {
+          if (err)
+          {
+            jalview.bin.Console.errPrintln(message);
+          }
+          else
+          {
+            jalview.bin.Console.outPrintln(message);
+          }
+        }
+      } catch (Exception e)
+      {
+        e.printStackTrace();
+      } catch (NoClassDefFoundError t)
+      {
+        hasConsole = false;
+        System.err.println(
+                "jalview.util.ErrorLog has no jalview.bin.Console. Using System.err and System.out.");
+      }
+    }
+    if (!hasConsole)
+    {
+      if (err)
+      {
+        System.err.println("jalview.util.ErrorLog: " + message);
+      }
+      else
+      {
+        System.out.println("jalview.util.ErrorLog: " + message);
+
+      }
+    }
+  }
+}