Example usage for org.apache.commons.logging Log fatal

List of usage examples for org.apache.commons.logging Log fatal

Introduction

In this page you can find the example usage for org.apache.commons.logging Log fatal.

Prototype

void fatal(Object message, Throwable t);

Source Link

Document

Logs an error with fatal log level.

Usage

From source file:net.sf.jabb.util.ex.LoggedException.java

/**
 * Create a new instance, and at the same time, ensure the original exception is logged.
 * //from   ww w  . j ava  2s.co m
 * @param log      the log utility
 * @param level      level of the log
 * @param message   description
 * @param cause      the original exception. If it is of type LoggedException, 
 *                then the newly created instance is a clone of itself.
 */
public LoggedException(Log log, int level, String message, Throwable cause) {
    super(cause instanceof LoggedException ? cause.getMessage() : message,
            cause instanceof LoggedException ? cause.getCause() : cause);
    if (!(cause instanceof LoggedException)) {
        switch (level) {
        case TRACE:
            if (log.isTraceEnabled()) {
                log.trace(message, cause);
            }
            break;
        case DEBUG:
            if (log.isDebugEnabled()) {
                log.debug(message, cause);
            }
            break;
        case WARN:
            if (log.isWarnEnabled()) {
                log.warn(message, cause);
            }
            break;
        case FATAL:
            log.fatal(message, cause);
            break;
        case INFO:
            log.info(message, cause);
            break;
        default:
            log.error(message, cause);
        }
    }
}

From source file:com.flexive.shared.exceptions.FxApplicationException.java

/**
 * Log a message at a given level (or error if no level given)
 *
 * @param log     Log to use/* w  w w  .  ja  v  a 2 s. c  om*/
 * @param message message to LOG
 * @param level   log4j level to apply
 */
private void logMessage(Log log, String message, LogLevel level) {
    this.messageLogged = true;
    if (FxContext.get() != null && FxContext.get().isTestDivision())
        return; //dont log exception traces during automated tests
    final Throwable cause = getCause() != null ? getCause() : this;
    if (level == null)
        log.error(message, cause);
    else {
        switch (level) {
        case DEBUG:
            if (log.isDebugEnabled())
                log.debug(message);
            break;
        case ERROR:
            if (log.isErrorEnabled())
                log.error(message, cause);
            break;
        case FATAL:
            if (log.isFatalEnabled())
                log.fatal(message, cause);
            break;
        case INFO:
            if (log.isInfoEnabled())
                log.info(message);
            break;
        //                case Level.WARN_INT:
        default:
            if (log.isWarnEnabled())
                log.warn(message);
        }
    }
}

From source file:net.wastl.webmail.xml.XMLCommon.java

/**
 * Logs a XML dump to the specified Log instanance.
 *
 * <P>For brevity and simplicity, callers may want to import level
 * constants like this so they can juse use like "LOG_LEVEL_DEBUG":
import static org.apache.commons.logging.impl.SimpleLog.*;
 * </P>//from   w w  w.j a  va 2s .c o  m
 * N.b. the calling method and location can't be identified by this
 * method.  If you need that kind of detail, make a direct log call
 * before calling this method.
 *
 * @param log  Target Log instance
 * @param label Leading log message
 * @param level A org.apache.commons.logging.impl.SimpleLog constant.
 *              I don't know why Commons doesn't have a simple log()
 *              method and Log.X constants like Log4j does.  :(
 * @param doc The XML document to dump
 */
public static synchronized void dumpXML(Log log, int level, String label, Document doc) {
    String methodName = null;
    switch (level) {
    case LOG_LEVEL_DEBUG:
        methodName = "debug";
        break;
    case LOG_LEVEL_ERROR:
        methodName = "error";
        break;
    case LOG_LEVEL_FATAL:
        methodName = "fatal";
        break;
    case LOG_LEVEL_INFO:
        methodName = "info";
        break;
    case LOG_LEVEL_TRACE:
        methodName = "trace";
        break;
    case LOG_LEVEL_WARN:
        methodName = "warn";
        break;
    }
    if (methodName == null)
        throw new IllegalArgumentException("Unexpected level specification " + level
                + "\nSee API spec document for " + SimpleLog.class.getName());
    try {
        java.lang.reflect.Method logMethod = Log.class.getMethod(methodName, Object.class);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        writeXML(doc, baos, "test");
        baos.flush();
        logMethod.invoke(log, label + "\n" + baos);
    } catch (Exception ex) {
        log.fatal("Failed to log XML document details", ex);
        return;
    }
}

From source file:org.acmsl.queryj.customsql.AbstractCustomSqlProvider.java

/**
 * Computes the hash of given String./* w w  w  . ja v a 2  s .co m*/
 * @param value the value.
 * @param charset the charset.
 * @return the hash.
 */
@NotNull
protected String getHash(@NotNull final String value, @NotNull final String charset) {
    @Nullable
    String result = null;

    try {
        @NotNull
        final MessageDigest t_MessageDigest = MessageDigest.getInstance("SHA1");

        result = URLEncoder.encode(
                DatatypeConverter.printBase64Binary(t_MessageDigest.digest(value.getBytes(charset))), charset);
    } catch (@NotNull final NoSuchAlgorithmException noSuchAlgorithm) {
        @Nullable
        final Log t_Log = UniqueLogFactory.getLog(SqlXmlParser.class);

        if (t_Log != null) {
            t_Log.fatal("Cannot use SHA1 for computing hashes", noSuchAlgorithm);
        }
    } catch (@NotNull final UnsupportedEncodingException unsupportedEncoding) {
        @Nullable
        final Log t_Log = UniqueLogFactory.getLog(SqlXmlParser.class);

        if (t_Log != null) {
            t_Log.fatal("Cannot use UTF-8 for encoding hashes", unsupportedEncoding);
        }
    }

    if (result == null) {
        result = "";
    }

    return result;
}

From source file:org.acmsl.queryj.metadata.engines.JdbcTypeManager.java

/**
 * Calls the correct method on {@link PreparedStatement} to set the parameter.
 * @param statement the {@link PreparedStatement}.
 * @param index the parameter index.//from w w w.jav a 2s  .  c o m
 * @param value the parameter value.
 * @param <T> the parameter class.
 */
protected <T> void setPreparedStatementParameter(@NotNull final PreparedStatement statement, final int index,
        @NotNull final T value) {
    @NotNull
    final Method t_Method = getPreparedStatementSetterMethod(findOutClass(value));

    try {
        t_Method.invoke(statement, index, value);
    } catch (@NotNull final InvocationTargetException invalidMethodOrParams) {
        @Nullable
        final Log t_Log = UniqueLogFactory.getLog(JdbcTypeManager.class);

        if (t_Log != null) {
            t_Log.fatal(CANNOT_SET_PARAMETER + value + ON_PREPARED_STATEMENT, invalidMethodOrParams);
        }
    } catch (@NotNull final IllegalAccessException invalidMethodOrParams) {
        @Nullable
        final Log t_Log = UniqueLogFactory.getLog(JdbcTypeManager.class);

        if (t_Log != null) {
            t_Log.fatal(CANNOT_SET_PARAMETER + value + ON_PREPARED_STATEMENT, invalidMethodOrParams);
        }
    }
}

From source file:org.alfresco.extension.bulkimport.util.LogUtils.java

public final static void fatal(final Log log, final String message, final Throwable cause) {
    log.fatal(PREFIX + message, cause);
}

From source file:org.alfresco.extension.bulkimport.util.LogUtils.java

public final static void fatal(final Log log, final Throwable cause) {
    log.fatal(RAW_EXCEPTION, cause);
}

From source file:org.amplafi.flow.impl.FlowStateLoggerImpl.java

public void fatal(Log logger, Object message, Throwable throwable) {
    if (logger == null) {
        logger = getLog();/*  w ww  .java 2s  . co m*/
    }
    StringBuilder stringBuilder = getFlowStatesString(message);
    logger.fatal(stringBuilder, throwable);
}

From source file:org.cloudata.core.common.testhelper.ProxyExceptionHelper.java

public static void handleException(UndeclaredThrowableException e, Log LOG) throws IOException {
    if (e.getUndeclaredThrowable() instanceof InvocationTargetException) {
        InvocationTargetException ex = ((InvocationTargetException) e.getUndeclaredThrowable());
        if (ex.getTargetException() instanceof IOException) {
            throw (IOException) ex.getTargetException();
        } else {//w  w w.  j  a v a2 s  .c  o m
            LOG.fatal("Unexpected exception is occurred", ex.getTargetException());
            throw new IOException("Unexpected exception is occurred : " + e, e);
        }
    } else {
        LOG.fatal("Unexpected exception is occurred", e);
        throw new IOException("Unexpected exception is occurred : " + e, e);
    }

}

From source file:org.cruk.genologics.api.unittests.UnitTestApplicationContextFactory.java

public static boolean setCredentialsOnApi(GenologicsAPI api) {
    InputStream propsIn = UnitTestApplicationContextFactory.class
            .getResourceAsStream("/testcredentials.properties");
    if (propsIn != null) {
        try {//from www.ja v  a2  s .  c  o m
            Properties credentials = new Properties();
            credentials.load(propsIn);
            api.setConfiguration(credentials);
            return true;
        } catch (IOException e) {
            Log logger = LogFactory.getLog(UnitTestApplicationContextFactory.class);
            logger.fatal("Could not read from credentials file: ", e);
        } finally {
            IOUtils.closeQuietly(propsIn);
        }
    }
    return false;
}