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