From: Ben Soares Date: Fri, 11 Feb 2022 15:43:30 +0000 (+0000) Subject: JLogger loglevel check on whether to call the actual logger or not. New factory metho... X-Git-Tag: Release_2_11_2_0~13^2^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a2214909ebf9788ca5c6386f1f1675efe3d02b9b;p=jalview.git JLogger loglevel check on whether to call the actual logger or not. New factory methods with Class. --- diff --git a/src/jalview/io/vamsas/DatastoreItem.java b/src/jalview/io/vamsas/DatastoreItem.java index e20f51e..6bfddb7 100644 --- a/src/jalview/io/vamsas/DatastoreItem.java +++ b/src/jalview/io/vamsas/DatastoreItem.java @@ -61,7 +61,7 @@ public abstract class DatastoreItem * shared log instance */ protected static JLoggerLog4j log = JLoggerLog4j - .getLogger(DatastoreItem.class.getCanonicalName()); + .getLogger(DatastoreItem.class); /** * note: this is taken verbatim from jalview.io.VamsasAppDatastore diff --git a/src/jalview/io/vamsas/DatastoreRegistry.java b/src/jalview/io/vamsas/DatastoreRegistry.java index fe5a917..233685b 100644 --- a/src/jalview/io/vamsas/DatastoreRegistry.java +++ b/src/jalview/io/vamsas/DatastoreRegistry.java @@ -29,7 +29,7 @@ import jalview.log.JLoggerLog4j; public class DatastoreRegistry implements AutoCloseable { protected static JLoggerLog4j log = JLoggerLog4j - .getLogger(DatastoreRegistry.class.getCanonicalName()); + .getLogger(DatastoreRegistry.class); /** * map between Datastore objects and the objects they are handling- used to diff --git a/src/jalview/log/JLogger.java b/src/jalview/log/JLogger.java index 03b664a..7a6054e 100644 --- a/src/jalview/log/JLogger.java +++ b/src/jalview/log/JLogger.java @@ -38,6 +38,16 @@ public abstract class JLogger implements JLoggerI } } + public static JLogger getLogger(Class c) + { + return getLogger(c); + } + + public static JLogger getLogger(Class c, LogLevel loglevel) + { + return getLogger(c.getCanonicalName(), loglevel); + } + public static JLogger getLogger(String name) { return getLogger(name, LogLevel.INFO); @@ -87,15 +97,20 @@ public abstract class JLogger implements JLoggerI loggerSetLevel(level); } - private boolean println(LogLevel level, String message, Throwable t) + private boolean println(LogLevel loglevel, String message, Throwable t) { + if (loglevel.compareTo(this.level) < 0) + { + return false; + } if (!loggerExists() || Platform.isJS()) { - String logLine = String.format("%s: %s", level.toString(), message); + String logLine = String.format("%s: %s", loglevel.toString(), + message); System.out.println(logLine); if (t != null) { - if (level.compareTo(LogLevel.DEBUG) <= 0) + if (loglevel.compareTo(LogLevel.DEBUG) <= 0) t.printStackTrace(System.err); else System.err.println(t.getMessage()); @@ -104,7 +119,7 @@ public abstract class JLogger implements JLoggerI } else { - loggerLogMessage(level, message, t); + loggerLogMessage(loglevel, message, t); return true; } } diff --git a/src/jalview/log/JLoggerLog4j.java b/src/jalview/log/JLoggerLog4j.java index ca24e30..bacab74 100644 --- a/src/jalview/log/JLoggerLog4j.java +++ b/src/jalview/log/JLoggerLog4j.java @@ -10,6 +10,16 @@ public class JLoggerLog4j extends JLogger implements JLoggerI { private Logger logger = null; + public static JLoggerLog4j getLogger(Class c) + { + return getLogger(c); + } + + public static JLoggerLog4j getLogger(Class c, LogLevel loglevel) + { + return getLogger(c.getCanonicalName(), loglevel); + } + public static JLoggerLog4j getLogger(String name) { return getLogger(name, LogLevel.INFO); @@ -23,7 +33,6 @@ public class JLoggerLog4j extends JLogger implements JLoggerI private JLoggerLog4j(String name, LogLevel level) { - // super(name, level); this.name = name; this.level = level; this.loggerSetup(); @@ -120,11 +129,11 @@ public class JLoggerLog4j extends JLogger implements JLoggerI return this.logger; } - public synchronized static void addAppender(JLoggerLog4j l1, + public synchronized static void addAppender(JLoggerLog4j level, Appender appender) { if (!Platform.isJS()) - Log4j.addAppender(l1.getLoggerObject(), appender); + Log4j.addAppender(level.getLoggerObject(), appender); } public synchronized static void addAppender(JLoggerLog4j l1,