This repository has been archived on 2025-12-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tcommon-studio-se/org.talend.commons.runtime/src/org/talend/commons/exception/CommonExceptionHandler.java
mwang 212d0126c3 For bug TUP-221
git-svn-id: http://talendforge.org/svn/tos/branches/branch-5_1@93332 f6f1c999-d317-4740-80b0-e6d1abc6f99e
2012-11-07 04:21:28 +00:00

83 lines
2.4 KiB
Java

// ============================================================================
//
// Copyright (C) 2006-2012 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.commons.exception;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.talend.commons.i18n.internal.Messages;
/**
* Implementation of exception handling strategy.<br/>
*
* $Id: ExceptionHandler.java 7038 2007-11-15 14:05:48Z plegall $
*
*/
public final class CommonExceptionHandler {
private static Logger log = Logger.getLogger(CommonExceptionHandler.class);
/**
* Empty constructor.
*/
private CommonExceptionHandler() {
}
/**
* Log message relative to ex param. Log level depends on exception type.
*
* @param ex - exception to log
*/
public static void process(Throwable ex) {
Priority priority = getPriority(ex);
process(ex, priority);
}
public static void process(Throwable ex, Priority priority) {
String message = ex.getMessage();
log.log(priority, message, ex);
}
public static void log(String message) {
log.log(Level.INFO, message);
}
public static void warn(String message) {
log.log(Level.WARN, message);
}
/**
* Return priority corresponding to the exception implementation.
*
* @param ex - the exception to evaluate priority
* @return the priority corresponding to the exception implementation
*/
public static Priority getPriority(Throwable ex) {
if (ex == null) {
throw new IllegalArgumentException(Messages.getString("ExceptionHandler.Parameter.BeNull")); //$NON-NLS-1$
}
if (ex instanceof BusinessException) {
return Level.INFO;
} else if (ex instanceof FatalException) {
return Level.FATAL;
} else if (ex instanceof SystemException) {
return Level.WARN;
} else {
return Level.ERROR;
}
}
}