X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2FLogger.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2FLogger.java;h=ad93cb85ba1012f39aa6320978767a8bbbc65625;hp=a9c9b032371fd1b1240aced346568741dab48a89;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/Logger.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/Logger.java index a9c9b0323..ad93cb85b 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/Logger.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/Logger.java @@ -1,107 +1,107 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram; - -import java.util.Properties; - -public class Logger { - public static final boolean ECHO = false; - public static final Properties defaultProperties = new Properties(); - static { - defaultProperties.put("log4j.rootCategory", "ERROR, default"); - defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender"); - defaultProperties.put("log4j.appender.default.File", "diagram.log"); - defaultProperties.put("log4j.appender.default.append", "false"); - defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout"); - defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r [%15.15t] %-5p %30.30c - %m%n"); - } - private static LogManager defaultLogManager = new LogManager(defaultProperties); - private static final Logger defaultErrorLogger = new Logger(LogManager.class); - private org.apache.log4j.Logger logger; - Logger(Class clazz) { - logger = defaultLogManager.getLogger(clazz); - } - - /** - * Log a trace event. - * - * @param message message of the trace - * @param exception the exception, or null - */ - public void logTrace(String message, Throwable exception) { - // Errors are much more useful with a stack trace! - if (exception == null) { - exception = new RuntimeException(); - } - logger.trace(message, exception); - } - - /** - * Log an info event. - * - * @param message message of the info - * @param exception the exception, or null - */ - public void logInfo(String message, Throwable exception) { - // Errors are much more useful with a stack trace! - if (exception == null) { - exception = new RuntimeException(); - } - logger.info(message, exception); - } - - /** - * Log an error event. - * - * @param message message of the error - * @param exception the exception, or null - */ - public void logError(String message, Throwable exception) { - // Errors are much more useful with a stack trace! - if (exception == null) { - exception = new RuntimeException(); - } - logger.error(message, exception); - } - - public static Logger getDefault() { - return defaultErrorLogger; - } - - public static LogManager getDefaultLogManager() { - return defaultLogManager; - } - public static void defaultLogError(Throwable exception) { - getDefault().logError(exception.getLocalizedMessage(), exception); - if(ECHO) exception.printStackTrace(); - } - public static void defaultLogError(String message) { - getDefault().logError(message, null); - if(ECHO) - System.err.println(message); - } - public static void defaultLogError(String message, Throwable exception) { - getDefault().logError(message, exception); - if(ECHO) - System.err.println(message); - } - public static void defaultLogInfo(String message) { - getDefault().logInfo(message, null); - if(ECHO) - System.err.println(message); - } - public static void defaultLogTrace(String message) { - getDefault().logTrace(message, null); - if(ECHO) - System.err.println(message); - } -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram; + +import java.util.Properties; + +public class Logger { + public static final boolean ECHO = false; + public static final Properties defaultProperties = new Properties(); + static { + defaultProperties.put("log4j.rootCategory", "ERROR, default"); + defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender"); + defaultProperties.put("log4j.appender.default.File", "diagram.log"); + defaultProperties.put("log4j.appender.default.append", "false"); + defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout"); + defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r [%15.15t] %-5p %30.30c - %m%n"); + } + private static LogManager defaultLogManager = new LogManager(defaultProperties); + private static final Logger defaultErrorLogger = new Logger(LogManager.class); + private org.apache.log4j.Logger logger; + Logger(Class clazz) { + logger = defaultLogManager.getLogger(clazz); + } + + /** + * Log a trace event. + * + * @param message message of the trace + * @param exception the exception, or null + */ + public void logTrace(String message, Throwable exception) { + // Errors are much more useful with a stack trace! + if (exception == null) { + exception = new RuntimeException(); + } + logger.trace(message, exception); + } + + /** + * Log an info event. + * + * @param message message of the info + * @param exception the exception, or null + */ + public void logInfo(String message, Throwable exception) { + // Errors are much more useful with a stack trace! + if (exception == null) { + exception = new RuntimeException(); + } + logger.info(message, exception); + } + + /** + * Log an error event. + * + * @param message message of the error + * @param exception the exception, or null + */ + public void logError(String message, Throwable exception) { + // Errors are much more useful with a stack trace! + if (exception == null) { + exception = new RuntimeException(); + } + logger.error(message, exception); + } + + public static Logger getDefault() { + return defaultErrorLogger; + } + + public static LogManager getDefaultLogManager() { + return defaultLogManager; + } + public static void defaultLogError(Throwable exception) { + getDefault().logError(exception.getLocalizedMessage(), exception); + if(ECHO) exception.printStackTrace(); + } + public static void defaultLogError(String message) { + getDefault().logError(message, null); + if(ECHO) + System.err.println(message); + } + public static void defaultLogError(String message, Throwable exception) { + getDefault().logError(message, exception); + if(ECHO) + System.err.println(message); + } + public static void defaultLogInfo(String message) { + getDefault().logInfo(message, null); + if(ECHO) + System.err.println(message); + } + public static void defaultLogTrace(String message) { + getDefault().logTrace(message, null); + if(ECHO) + System.err.println(message); + } +}