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.db.common.utils;
14 import java.util.Properties;
16 import org.apache.log4j.Logger;
20 * @deprecated in favor of org.simantics.db.common.Logger. Will be removed in Simantics 1.2
24 public class ErrorLogger {
25 public static final boolean ECHO = false;
26 public static final Properties defaultProperties = new Properties();
28 defaultProperties.put("log4j.rootCategory", "ERROR, default");
29 defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender");
30 defaultProperties.put("log4j.appender.default.File", "db-client-deprecated.log");
31 defaultProperties.put("log4j.appender.default.append", "false");
32 defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout");
33 defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r [%15.15t] %-5p %30.30c - %m%n");
35 private static LogManager defaultLogManager = new LogManager(defaultProperties);
36 private static final ErrorLogger defaultErrorLogger = new ErrorLogger(LogManager.class);
37 private Logger logger;
38 ErrorLogger(Class<?> clazz) {
39 logger = defaultLogManager.getLogger(clazz);
45 * @param message message of the trace
46 * @param exception the exception, or <code>null</code>
48 public void logTrace(String message, Throwable exception) {
49 // Errors are much more useful with a stack trace!
50 if (exception == null) {
51 exception = new RuntimeException();
53 logger.trace(message, exception);
59 * @param message message of the info
60 * @param exception the exception, or <code>null</code>
62 public void logInfo(String message, Throwable exception) {
63 // Errors are much more useful with a stack trace!
64 if (exception == null) {
65 exception = new RuntimeException();
67 logger.info(message, exception);
73 * @param message message of the error
74 * @param exception the exception, or <code>null</code>
76 public void logError(String message, Throwable exception) {
77 // Errors are much more useful with a stack trace!
78 if (exception == null) {
79 exception = new RuntimeException();
81 logger.error(message, exception);
84 public static ErrorLogger getDefault() {
85 return defaultErrorLogger;
88 public static LogManager getDefaultLogManager() {
89 return defaultLogManager;
91 public static void defaultLogError(Throwable exception) {
92 getDefault().logError(exception.getLocalizedMessage(), exception);
93 if(ECHO) exception.printStackTrace();
95 public static void defaultLogError(String message) {
96 getDefault().logError(message, null);
98 System.err.println(message);
100 public static void defaultLogError(String message, Throwable exception) {
101 getDefault().logError(message, exception);
103 System.err.println(message);
105 public static void defaultLogInfo(String message) {
106 getDefault().logInfo(message, null);
108 System.err.println(message);
110 public static void defaultLogTrace(String message) {
111 getDefault().logTrace(message, null);
113 System.err.println(message);