]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.common/src/org/simantics/db/common/utils/Logger.java
Goodbye db-client.log
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / utils / Logger.java
index 1013051b7e7b12c80d4aa950193639f75b2272ef..01f15e0b51027a6b5a775406807bdc7231983610 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.common.utils;\r
-\r
-import java.util.Properties;\r
-\r
-import org.apache.log4j.Level;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.DevelopmentKeys;\r
-import org.simantics.db.common.internal.config.InternalClientConfig;\r
-import org.simantics.utils.Development;\r
-\r
-public class Logger {\r
-    public static final boolean ENABLED = true;\r
-    //public static final boolean ECHO = Development.DEVELOPMENT || false;\r
-    public static final Properties defaultProperties = new Properties();\r
-    static {\r
-        defaultProperties.put("log4j.rootCategory", "ERROR, default");\r
-        defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender");\r
-        defaultProperties.put("log4j.appender.default.File", InternalClientConfig.DB_CLIENT_LOG_FILE);\r
-        defaultProperties.put("log4j.appender.default.append", "true");\r
-        defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout");\r
-        defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%d{ISO8601} %-6r [%15.15t] %-5p %30.30c - %m%n");\r
-    }\r
-    private static LogManager defaultLogManager = new LogManager(defaultProperties);\r
-    private static final Logger defaultErrorLogger = new Logger(LogManager.class);\r
-    private org.apache.log4j.Logger logger;\r
-    Logger(Class<?> clazz) {\r
-        logger = defaultLogManager.getLogger(clazz);\r
-    }\r
-\r
-    /**\r
-     * Log a trace event.\r
-     *\r
-     * @param message message of the trace\r
-     * @param exception the exception, or <code>null</code>\r
-     */\r
-    public void logTrace(String message, Throwable exception) {\r
-\r
-        if(!logger.isTraceEnabled()) return;\r
-\r
-        // Errors are much more useful with a stack trace!\r
-        if (exception == null) {\r
-            exception = new RuntimeException();\r
-        }\r
-        logger.trace(message, exception);\r
-\r
-        if (Development.DEVELOPMENT) {\r
-            if(Development.<Boolean>getProperty(DevelopmentKeys.LOGGER_ECHO, Bindings.BOOLEAN)) {\r
-                System.err.println("Logger.logTrace: " + message);\r
-            }\r
-        }\r
-\r
-    }\r
-\r
-    /**\r
-     * Log an info event.\r
-     *\r
-     * @param message message of the info\r
-     * @param exception the exception, or <code>null</code>\r
-     */\r
-    public void logInfo(String message, Throwable exception) {\r
-\r
-        if(!logger.isInfoEnabled()) return;\r
-\r
-        // Errors are much more useful with a stack trace!\r
-        if (exception == null) {\r
-            exception = new RuntimeException();\r
-        }\r
-        logger.info(message, exception);\r
-\r
-        if (Development.DEVELOPMENT) {\r
-            if(Development.<Boolean>getProperty(DevelopmentKeys.LOGGER_ECHO, Bindings.BOOLEAN)) {\r
-                System.err.println("Logger.logInfo: " + message);\r
-            }\r
-        }\r
-\r
-    }\r
-\r
-    /**\r
-     * Log an error event.\r
-     *\r
-     * @param message message of the error\r
-     * @param exception the exception, or <code>null</code>\r
-     */\r
-    public void logError(String message, Throwable exception) {\r
-\r
-        if(!logger.isEnabledFor(Level.ERROR)) return;\r
-\r
-        // Errors are much more useful with a stack trace!\r
-        if (exception == null) {\r
-            exception = new RuntimeException();\r
-        }\r
-        logger.error(message, exception);\r
-\r
-        if (Development.DEVELOPMENT) {\r
-            if(Development.<Boolean>getProperty(DevelopmentKeys.LOGGER_ECHO, Bindings.BOOLEAN)) {\r
-                System.err.println("Logger.logError: " + message);\r
-            }\r
-        }\r
-\r
-    }\r
-\r
-    /**\r
-     * Log an error event.\r
-     *\r
-     * @param message message of the error\r
-     * @param exception the exception, or <code>null</code>\r
-     */\r
-    public void logWarning(String message, Throwable exception) {\r
-\r
-        if(!logger.isEnabledFor(Level.WARN)) return;\r
-\r
-        // Errors are much more useful with a stack trace!\r
-        if (exception == null) {\r
-            exception = new RuntimeException();\r
-        }\r
-        logger.error(message, exception);\r
-\r
-        if (Development.DEVELOPMENT) {\r
-            if(Development.<Boolean>getProperty(DevelopmentKeys.LOGGER_ECHO, Bindings.BOOLEAN)) {\r
-                System.err.println("Logger.logWarning: " + message);\r
-            }\r
-        }\r
-\r
-    }\r
-\r
-    /**\r
-     * Log message.\r
-     *\r
-     * @param message to log.\r
-     */\r
-    public void logMessage(String message) {\r
-        Level level = logger.getLevel();\r
-        boolean toggle = !logger.isInfoEnabled();\r
-        if (toggle)\r
-            logger.setLevel((Level)Level.INFO);\r
-        logger.info(message);\r
-        if (toggle)\r
-            logger.setLevel(level);\r
-        if (Development.DEVELOPMENT) {\r
-            if(Development.<Boolean>getProperty(DevelopmentKeys.LOGGER_ECHO, Bindings.BOOLEAN)) {\r
-                System.err.println("Logger.logMessage: " + message);\r
-            }\r
-        }\r
-    }\r
-\r
-    public static Logger getDefault() {\r
-        return defaultErrorLogger;\r
-    }\r
-\r
-    public static LogManager getDefaultLogManager() {\r
-        return defaultLogManager;\r
-    }\r
-    public static void defaultLogError(Throwable exception) {\r
-        if(!ENABLED) return;\r
-        getDefault().logError(exception.getLocalizedMessage(), exception);\r
-    }\r
-    public static void defaultLogError(String message) {\r
-        if(!ENABLED) return;\r
-        getDefault().logError(message, null);\r
-    }\r
-    public static void defaultLogError(String message, Throwable exception) {\r
-        if(!ENABLED) return;\r
-        getDefault().logError(message, exception);\r
-    }\r
-    public static void defaultLogInfo(String message) {\r
-        if(!ENABLED) return;\r
-        getDefault().logInfo(message, null);\r
-    }\r
-    public static void defaultLogTrace(String message) {\r
-        if(!ENABLED) return;\r
-        getDefault().logTrace(message, null);\r
-    }\r
-    public static void defaultLog(String message) {\r
-        if(!ENABLED) return;\r
-        getDefault().logMessage(message);\r
-    }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010, 2018 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *     Semantum Oy - Deprecating and replace with SLF4J Logger
+ *******************************************************************************/
+package org.simantics.db.common.utils;
+
+import org.slf4j.LoggerFactory;
+
+@Deprecated
+public class Logger {
+
+    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Logger.class);
+    private static final String TODO_REPLACE_RIGHT_LOGGER = "[TODO: Replace with right logger instance]";
+
+    public static void defaultLogError(Throwable exception) {
+        LOGGER.error(TODO_REPLACE_RIGHT_LOGGER, exception);
+    }
+    public static void defaultLogError(String message) {
+        LOGGER.error("{} {}", TODO_REPLACE_RIGHT_LOGGER, message);
+    }
+    public static void defaultLogError(String message, Throwable exception) {
+        LOGGER.error("{} {}", TODO_REPLACE_RIGHT_LOGGER, message, exception);
+    }
+    public static void defaultLogInfo(String message) {
+        LOGGER.info("{} {}", TODO_REPLACE_RIGHT_LOGGER, message);
+    }
+}