1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.utils.logging;
\r
14 import java.util.Properties;
\r
16 abstract public class Logger {
\r
18 public static final boolean ECHO = false;
\r
20 protected static final Properties defaultProperties(String ... keyValuePairs) {
\r
22 assert(keyValuePairs.length % 2 == 0);
\r
24 Properties defaultProperties = new Properties();
\r
25 defaultProperties.put("log4j.rootCategory", "ERROR, default");
\r
26 defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender");
\r
27 defaultProperties.put("log4j.appender.default.append", "false");
\r
28 defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout");
\r
29 defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r [%15.15t] %-5p %30.30c - %m%n");
\r
31 for(int i=0;i<keyValuePairs.length;) {
\r
32 String key = keyValuePairs[i++];
\r
33 String value = keyValuePairs[i++];
\r
34 defaultProperties.put(key, value);
\r
37 return defaultProperties;
\r
41 final protected org.apache.log4j.Logger logger;
\r
43 protected Logger(org.apache.log4j.Logger logger) {
\r
44 this.logger = logger;
\r
47 final protected org.apache.log4j.Logger getLogger() {
\r
52 * Log a trace event.
\r
54 * @param message message of the trace
\r
55 * @param exception the exception, or <code>null</code>
\r
57 public void logTrace(String message, Throwable exception) {
\r
58 // Errors are much more useful with a stack trace!
\r
59 if (exception == null) {
\r
60 exception = new RuntimeException();
\r
62 getLogger().trace(message, exception);
\r
66 * Log an info event.
\r
68 * @param message message of the info
\r
69 * @param exception the exception, or <code>null</code>
\r
71 public void logInfo(String message, Throwable exception) {
\r
72 // Errors are much more useful with a stack trace!
\r
73 if (exception == null) {
\r
74 exception = new RuntimeException();
\r
76 getLogger().info(message, exception);
\r
80 * Log an error event.
\r
82 * @param message message of the error
\r
83 * @param exception the exception, or <code>null</code>
\r
85 public void logError(String message, Throwable exception) {
\r
87 // Errors are much more useful with a stack trace!
\r
88 if (exception == null) {
\r
89 exception = new RuntimeException();
\r
91 getLogger().error(message, exception);
\r
95 * Log an error event.
\r
97 * @param message message of the error
\r
98 * @param exception the exception, or <code>null</code>
\r
100 public void logWarning(String message, Throwable exception) {
\r
101 // Errors are much more useful with a stack trace!
\r
102 if (exception == null) {
\r
103 exception = new RuntimeException();
\r
105 getLogger().error(message, exception);
\r