From 42badb1235a87eab88dc14caf579d1230c9d0560 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Mon, 24 Aug 2020 21:06:16 +0300 Subject: [PATCH] Replace log4j with slf4j gitlab simantics/platform#579 --- .../META-INF/MANIFEST.MF | 4 +- .../org/simantics/interop/mapping/Logger.java | 133 ------------------ .../org/simantics/interop/mapping/Mapper.java | 8 +- .../interop/mapping/data/GraphNode.java | 19 +-- 4 files changed, 19 insertions(+), 145 deletions(-) delete mode 100644 org.simantics.interop.mapping/src/org/simantics/interop/mapping/Logger.java diff --git a/org.simantics.interop.mapping/META-INF/MANIFEST.MF b/org.simantics.interop.mapping/META-INF/MANIFEST.MF index 494937c..a3b1a17 100644 --- a/org.simantics.interop.mapping/META-INF/MANIFEST.MF +++ b/org.simantics.interop.mapping/META-INF/MANIFEST.MF @@ -10,9 +10,9 @@ Require-Bundle: org.eclipse.ui, org.simantics.db;bundle-version="1.1.0", org.simantics.db.common;bundle-version="1.1.0", org.simantics.diagram;bundle-version="1.1.1", - org.apache.log4j;bundle-version="1.2.15", org.simantics.db.layer0;bundle-version="1.1.0", - org.simantics.ui;bundle-version="1.0.0" + org.simantics.ui;bundle-version="1.0.0", + org.slf4j.api Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-ActivationPolicy: lazy Export-Package: org.simantics.interop.mapping, diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Logger.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Logger.java deleted file mode 100644 index 8ec1c07..0000000 --- a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Logger.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.simantics.interop.mapping; - -import java.util.Properties; - -import org.simantics.diagram.LogManager; - -public class Logger { - - - public static final boolean ECHO = false; - public static final boolean TRACE = false; - public static final Properties defaultProperties = new Properties(); - static { - defaultProperties.put("log4j.rootCategory", "INFO, default"); - defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender"); - defaultProperties.put("log4j.appender.default.File", "mapping.log"); - defaultProperties.put("log4j.appender.default.append", "false"); - defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout"); - defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r %-5p - %m%n"); - //defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r [%15.15t] %-5p %30.30c - %m%n"); - } - private static LogManager defaultLogManager = new LogManager(defaultProperties); - private static final Logger defaultErrorLogger = new Logger(LogManager.class); - private org.apache.log4j.Logger logger; - - Logger(Class clazz) { - logger = defaultLogManager.getLogger(clazz); - } - - /** - * Log a trace event. - * - * @param message message of the trace - * @param exception the exception, or null - */ - public void logTrace(String message, Throwable exception) { - // Errors are much more useful with a stack trace! - if (TRACE) { - if (exception == null) - exception = new RuntimeException(); - } - logger.trace(message, exception); - } - - /** - * Log an info event. - * - * @param message message of the info - * @param exception the exception, or null - */ - public void logInfo(String message, Throwable exception) { - // Errors are much more useful with a stack trace! - if (TRACE) { - if (exception == null) - exception = new RuntimeException(); - } - logger.info(message, exception); - } - - /** - * Log an warning event. - * @param message - * @param exception - */ - public void logWarning(String message, Throwable exception) { - // Errors are much more useful with a stack trace! - if (TRACE) { - if (exception == null) - exception = new RuntimeException(); - } - logger.warn(message, exception); - } - - - /** - * Log an error event. - * - * @param message message of the error - * @param exception the exception, or null - */ - public void logError(String message, Throwable exception) { - // Errors are much more useful with a stack trace! - if (TRACE) { - if (exception == null) - exception = new RuntimeException(); - } - logger.error(message, exception); - } - - public static Logger getDefault() { - return defaultErrorLogger; - } - - public static LogManager getDefaultLogManager() { - return defaultLogManager; - } - - public static void setDefaultThreshold(String level) { - getDefaultLogManager().setThreshold(level); - } - - public static void defaultLogError(Throwable exception) { - getDefault().logError(exception.getLocalizedMessage(), exception); - if(ECHO) exception.printStackTrace(); - } - public static void defaultLogError(String message) { - getDefault().logError(message, null); - if(ECHO) - System.err.println(message); - } - public static void defaultLogError(String message, Throwable exception) { - getDefault().logError(message, exception); - if(ECHO) - System.err.println(message); - } - public static void defaultLogInfo(String message) { - getDefault().logInfo(message, null); - if(ECHO) - System.err.println(message); - } - - public static void defaultLogWarning(String message) { - getDefault().logWarning(message, null); - if(ECHO) - System.err.println(message); - } - - public static void defaultLogTrace(String message) { - getDefault().logTrace(message, null); - if(ECHO) - System.err.println(message); - } -} diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Mapper.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Mapper.java index 5e74cf9..063f8ac 100644 --- a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Mapper.java +++ b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Mapper.java @@ -26,6 +26,8 @@ import org.simantics.interop.mapping.data.ResourceIdentifiable; import org.simantics.ui.jobs.SessionGarbageCollectorJob; import org.simantics.utils.datastructures.MapList; import org.simantics.utils.datastructures.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @@ -33,7 +35,9 @@ import org.simantics.utils.datastructures.Pair; * */ public class Mapper { - + + private static final Logger LOGGER = LoggerFactory.getLogger(Mapper.class); + public static final boolean USE_SPLIT_TRANSACTIONS = false; // Split transactions public static int OBJECTS_PER_TRANSACTION = 5000; // number of objects handled per transaction (split mode) private static boolean SLEEP_BETWEEN_WRITES = false; // sleep between transactions (split mode) @@ -744,7 +748,7 @@ public class Mapper { for (Pair r : connectionRules) { if (r.first.mathces(g, node, link.to(), link)) { - Logger.defaultLogInfo("Connecting " + getName(g, node.getData()) + " to " + getName(g, link.to().getData()) + " " + link.getName() + "/"+link.getInverseName()); + LOGGER.info("Connecting " + getName(g, node.getData()) + " to " + getName(g, link.to().getData()) + " " + link.getName() + "/"+link.getInverseName()); r.second.generate(g, node, link.to(), link); break; } diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/GraphNode.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/GraphNode.java index d9bbb50..cdebb51 100644 --- a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/GraphNode.java +++ b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/GraphNode.java @@ -6,8 +6,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.simantics.interop.mapping.Logger; import org.simantics.utils.datastructures.hints.HintContext; +import org.slf4j.Logger; /** @@ -18,6 +18,9 @@ import org.simantics.utils.datastructures.hints.HintContext; * @param */ public class GraphNode extends HintContext { + + private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(GraphNode.class); + protected T data; private List> nodes = new ArrayList>(); @@ -56,9 +59,9 @@ public class GraphNode extends HintContext { */ public Link addLink(String relationName, String inverseRelationName,GraphNode node) { _checkDisposed(); - Logger.defaultLogInfo("Node link " + data + " " + node.data + " " + relationName + " " + inverseRelationName +"\n"); + LOGGER.info("Node link " + data + " " + node.data + " " + relationName + " " + inverseRelationName +"\n"); if(containsLink(relationName, node) && node.containsLink(inverseRelationName, this)) { - Logger.defaultLogWarning("Node " + getData() + " has already given child " + node.getData() + " ,with name " + relationName + " / " + inverseRelationName); + LOGGER.warn("Node " + getData() + " has already given child " + node.getData() + " ,with name " + relationName + " / " + inverseRelationName); return null; } Link rel = _addLink(relationName,node); @@ -77,7 +80,7 @@ public class GraphNode extends HintContext { public Link addLink(String relationName,GraphNode node) { _checkDisposed(); if(containsLink(relationName, node)) { - Logger.defaultLogWarning("Node " + getData() + " has already given child " + node.getData() + " ,with name " + relationName ); + LOGGER.warn("Node " + getData() + " has already given child " + node.getData() + " ,with name " + relationName ); return null; } Link rel = _addLink(relationName,node); @@ -96,7 +99,7 @@ public class GraphNode extends HintContext { public Link addLink(Link link ,GraphNode node) { _checkDisposed(); if(containsLink(link.getName(), node) && node.containsLink(link.getInverseName(), this)) { - Logger.defaultLogWarning("Node " + getData() + " has already given child " + node.getData() + " ,with name " + link.getName() + " / " + link.getInverseName()); + LOGGER.warn("Node " + getData() + " has already given child " + node.getData() + " ,with name " + link.getName() + " / " + link.getInverseName()); return null; } Link rel = _addLink(link.getName(),node); @@ -718,7 +721,7 @@ public class GraphNode extends HintContext { public void destroy() { if (disposed) return; - Logger.defaultLogInfo("Node destroy " + data + " " + this); + LOGGER.info("Node destroy " + data + " " + this); Collection> coll = new ArrayList>(); coll.addAll(nodes); nodes.clear(); @@ -736,7 +739,7 @@ public class GraphNode extends HintContext { if (disposed) return; // FIXME: link.to may be *this. - Logger.defaultLogInfo("Node remove " + data + " " + this); + LOGGER.info("Node remove " + data + " " + this); if (nodes.size() == 1) { Link link = nodes.get(0); link.to().removeLink(link.getInverseName(), link.getName(), this); @@ -788,7 +791,7 @@ public class GraphNode extends HintContext { protected void _checkDisposed() { if (disposed) { - Logger.defaultLogError("Remove Node, disposed " + this); + LOGGER.error("Remove Node, disposed " + this); throw new RuntimeException("Node " + this + " is disposed."); } } -- 2.47.1