1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.diagram;
14 import java.util.Properties;
17 public static final boolean ECHO = false;
18 public static final Properties defaultProperties = new Properties();
20 defaultProperties.put("log4j.rootCategory", "ERROR, default");
21 defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender");
22 defaultProperties.put("log4j.appender.default.File", "diagram.log");
23 defaultProperties.put("log4j.appender.default.append", "false");
24 defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout");
25 defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r [%15.15t] %-5p %30.30c - %m%n");
27 private static LogManager defaultLogManager = new LogManager(defaultProperties);
28 private static final Logger defaultErrorLogger = new Logger(LogManager.class);
29 private org.apache.log4j.Logger logger;
30 Logger(Class<?> clazz) {
31 logger = defaultLogManager.getLogger(clazz);
37 * @param message message of the trace
38 * @param exception the exception, or <code>null</code>
40 public void logTrace(String message, Throwable exception) {
41 // Errors are much more useful with a stack trace!
42 if (exception == null) {
43 exception = new RuntimeException();
45 logger.trace(message, exception);
51 * @param message message of the info
52 * @param exception the exception, or <code>null</code>
54 public void logInfo(String message, Throwable exception) {
55 // Errors are much more useful with a stack trace!
56 if (exception == null) {
57 exception = new RuntimeException();
59 logger.info(message, exception);
65 * @param message message of the error
66 * @param exception the exception, or <code>null</code>
68 public void logError(String message, Throwable exception) {
69 // Errors are much more useful with a stack trace!
70 if (exception == null) {
71 exception = new RuntimeException();
73 logger.error(message, exception);
76 public static Logger getDefault() {
77 return defaultErrorLogger;
80 public static LogManager getDefaultLogManager() {
81 return defaultLogManager;
83 public static void defaultLogError(Throwable exception) {
84 getDefault().logError(exception.getLocalizedMessage(), exception);
85 if(ECHO) exception.printStackTrace();
87 public static void defaultLogError(String message) {
88 getDefault().logError(message, null);
90 System.err.println(message);
92 public static void defaultLogError(String message, Throwable exception) {
93 getDefault().logError(message, exception);
95 System.err.println(message);
97 public static void defaultLogInfo(String message) {
98 getDefault().logInfo(message, null);
100 System.err.println(message);
102 public static void defaultLogTrace(String message) {
103 getDefault().logTrace(message, null);
105 System.err.println(message);