--- /dev/null
+/*******************************************************************************\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.utils.logging;\r
+\r
+import java.util.Properties;\r
+\r
+abstract public class Logger {\r
+\r
+ public static final boolean ECHO = false;\r
+ \r
+ protected static final Properties defaultProperties(String ... keyValuePairs) {\r
+\r
+ assert(keyValuePairs.length % 2 == 0);\r
+ \r
+ Properties defaultProperties = new Properties();\r
+ defaultProperties.put("log4j.rootCategory", "ERROR, default");\r
+ defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender");\r
+ defaultProperties.put("log4j.appender.default.append", "false");\r
+ defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout");\r
+ defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r [%15.15t] %-5p %30.30c - %m%n");\r
+ \r
+ for(int i=0;i<keyValuePairs.length;) {\r
+ String key = keyValuePairs[i++];\r
+ String value = keyValuePairs[i++];\r
+ defaultProperties.put(key, value);\r
+ }\r
+ \r
+ return defaultProperties; \r
+ \r
+ }\r
+ \r
+ final protected org.apache.log4j.Logger logger;\r
+ \r
+ protected Logger(org.apache.log4j.Logger logger) {\r
+ this.logger = logger;\r
+ }\r
+\r
+ final protected org.apache.log4j.Logger getLogger() {\r
+ return logger;\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
+ // Errors are much more useful with a stack trace!\r
+ if (exception == null) {\r
+ exception = new RuntimeException();\r
+ }\r
+ getLogger().trace(message, exception);\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
+ // Errors are much more useful with a stack trace!\r
+ if (exception == null) {\r
+ exception = new RuntimeException();\r
+ }\r
+ getLogger().info(message, exception);\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
+ // Errors are much more useful with a stack trace!\r
+ if (exception == null) {\r
+ exception = new RuntimeException();\r
+ }\r
+ getLogger().error(message, exception);\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
+ // Errors are much more useful with a stack trace!\r
+ if (exception == null) {\r
+ exception = new RuntimeException();\r
+ }\r
+ getLogger().error(message, exception);\r
+ }\r
+ \r
+}\r