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

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

Introduction

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

Prototype

boolean isErrorEnabled();

Source Link

Document

Is error logging currently enabled?

Usage

From source file:com.sos.i18n.logging.commons.CommonsLogMsg.java

/**
 * Logs the given message to the log at the error level. If the log level is not enabled, this method does
 * nothing and returns <code>null</code>. If a message was logged, its {@link Msg} will be returned.
 *
 * <p>The given Throwable will be passed to the logger so its stack can be dumped when appropriate.</p>
 *
 * @param  log       the log where the messages will go
 * @param  throwable the throwable associated with the log message
 * @param  basename  the base name of the resource bundle
 * @param  locale    the locale to determine what bundle to use
 * @param  key       the resource bundle key name
 * @param  varargs   arguments to help fill in the resource bundle message
 *
 * @return if the message was logged, a non-<code>null</code> Msg object is returned
 *//*w  w  w  . j av a  2s.  c  o m*/
public static Msg error(Log log, Throwable throwable, BundleBaseName basename, Locale locale, String key,
        Object... varargs) {
    if (log.isErrorEnabled()) {
        Msg msg = Msg.createMsg(basename, locale, key, varargs);
        logErrorWithThrowable(log, key, msg, throwable);
        return msg;
    }

    return null;
}

From source file:fr.gouv.vitam.utils.logging.CommonsLoggerFactory.java

@Override
protected VitamLogLevel getLevelSpecific() {
    final Log logger = LogFactory.getFactory().getInstance("foo");
    if (logger.isTraceEnabled()) {
        return VitamLogLevel.TRACE;
    } else if (logger.isDebugEnabled()) {
        return VitamLogLevel.DEBUG;
    } else if (logger.isInfoEnabled()) {
        return VitamLogLevel.INFO;
    } else if (logger.isWarnEnabled()) {
        return VitamLogLevel.WARN;
    } else if (logger.isErrorEnabled()) {
        return VitamLogLevel.ERROR;
    }//from   w  ww .  ja  v a 2 s.  co  m
    return null;
}

From source file:com.netspective.axiom.connection.AbstractConnectionContext.java

public void rollbackAndCloseAndLogAsConnectionLeak(Log log, String message) {
    if (message == null)
        message = "** CONNECTION LEAK DETECTED ** Connection for DataSource '" + getDataSourceId()
                + "' not closed -- rolling back and forcing close now.\n";

    if (log.isErrorEnabled())
        log.error(message, getContextNotClosedException());
    else {/*  w  ww.ja  va2 s .c o m*/
        System.err.println(message);
        getContextNotClosedException().printStackTrace(System.err);
    }
    try {
        rollbackAndClose();
    } catch (SQLException e) {
        log.error("Unable to close leaking connection", e);
    }
}

From source file:com.siblinks.ws.common.BaseException.java

public void log(final Log log) {
    if (errorLevel.equals(ErrorLevel.INFO) && log.isDebugEnabled()) {
        log.debug("Info Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.debug(StackTracer.getStackTrace(throwable));
    } else if (errorLevel.equals(ErrorLevel.WARNING) && log.isWarnEnabled()) {
        log.warn("Warn Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.warn(StackTracer.getStackTrace(throwable));
    } else if (errorLevel.equals(ErrorLevel.ERROR) && log.isErrorEnabled()) {
        log.error("Error Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.error(StackTracer.getStackTrace(throwable));
    } else if (errorLevel.equals(ErrorLevel.FATAL) && log.isFatalEnabled()) {
        log.fatal("Fatal Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.fatal(StackTracer.getStackTrace(throwable));
    }//from  www  .  j a  va2 s.  co  m
    logged = true;
}

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  ww .j av  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:dk.statsbiblioteket.util.Logs.java

/**
 * Log the message and the elements to the log at the specified level.
 * Elements are converted to Strings and appended to the message. Arrays,
 * Lists and similar in the elements are expanded to a certain degree of
 * detail./*from  w w w  . ja  va2  s  .c  om*/
 *
 * Sample input/output:
 * <code>log(myLog, Level.TRACE, false, "Started test", null,
 * 5, new String[]{"flim", "flam"});</code>
 * expands to
 * <code>log.trace("Started test (5, (flim, flam))");</code>
 *
 * @param log      the log to log to.
 * @param level    the level to log to (e.g. TRACE, DEBUG, INFO...).
 * @param verbose  if true, the elements are expanded more than for false.
 * @param error    the cause of this logging. If null, no cause is logged.
 * @param message  the message for the log.
 * @param elements the elements to log.
 */
public static void log(Log log, Level level, String message, Throwable error, boolean verbose,
        Object... elements) {
    int maxLength = verbose ? VERBOSE_MAXLENGTH : DEFAULT_MAXLENGTH;
    int maxDepth = verbose ? VERBOSE_MAXDEPTH : DEFAULT_MAXDEPTH;
    String expanded = message;
    if (elements != null && elements.length > 0) {
        expanded += expand(elements, maxLength, maxDepth);
    }
    switch (level) {
    case TRACE:
        if (!log.isTraceEnabled()) {
            return;
        }
        if (error == null) {
            log.trace(expanded);
        } else {
            log.trace(expanded, error);
        }
        break;
    case DEBUG:
        if (!log.isDebugEnabled()) {
            return;
        }
        if (error == null) {
            log.debug(expanded);
        } else {
            log.debug(expanded, error);
        }
        break;
    case INFO:
        if (!log.isInfoEnabled()) {
            return;
        }
        if (error == null) {
            log.info(expanded);
        } else {
            log.info(expanded, error);
        }
        break;
    case WARN:
        if (!log.isWarnEnabled()) {
            return;
        }
        if (error == null) {
            log.warn(expanded);
        } else {
            log.warn(expanded, error);
        }
        break;
    case ERROR:
        if (!log.isErrorEnabled()) {
            return;
        }
        if (error == null) {
            log.error(expanded);
        } else {
            log.error(expanded, error);
        }
        break;
    case FATAL:
        if (!log.isFatalEnabled()) {
            return;
        }
        if (error == null) {
            log.fatal(expanded);
        } else {
            log.fatal(expanded, error);
        }
        break;
    default:
        throw new IllegalArgumentException("The level '" + level + "' is unknown");
    }
}

From source file:jp.terasoluna.fw.batch.util.BatchUtil.java

/**
 * ??//from w  w w .  j ava2 s .c  o  m
 * @param tranDef TransactionDefinition
 * @param tranMap PlatformTransactionManager
 * @param log Log
 * @return TransactionStatus
 */
public static Map<String, TransactionStatus> startTransactions(TransactionDefinition tranDef, Map<?, ?> tranMap,
        Log log) {
    Map<String, TransactionStatus> statMap = new LinkedHashMap<String, TransactionStatus>();

    if (!tranMap.isEmpty()) {
        for (Map.Entry<?, ?> ent : tranMap.entrySet()) {
            String key = null;
            PlatformTransactionManager ptm = null;

            // ??
            if (ent.getKey() instanceof String) {
                key = (String) ent.getKey();
            }
            // ???
            if (ent.getValue() instanceof PlatformTransactionManager) {
                ptm = (PlatformTransactionManager) ent.getValue();
            }

            if (ptm != null) {

                if (log != null && log.isDebugEnabled()) {
                    logDebug(log, LogId.DAL025033, key);
                    if (tranDef != null) {
                        logDebug(log, LogId.DAL025034, tranDef.getPropagationBehavior(),
                                tranDef.getIsolationLevel(), tranDef.getTimeout(), tranDef.isReadOnly(),
                                tranDef.getName());
                    }
                }

                // 
                TransactionStatus trnStat = null;
                try {
                    trnStat = ptm.getTransaction(tranDef);
                } catch (TransactionException e) {
                    if (log != null && log.isErrorEnabled()) {
                        logError(log, LogId.EAL025048, e, key);
                    }
                    endTransactions(tranMap, statMap, log);
                    throw e;
                }

                // ?
                if (statMap != null) {
                    statMap.put(key, trnStat);
                }

                if (log != null && log.isDebugEnabled()) {
                    logDebug(log, LogId.DAL025035, key, trnStat);
                }
            }
        }
    }

    return statMap;
}

From source file:jp.terasoluna.fw.batch.util.BatchUtil.java

/**
 * ???//from   w w  w  .j a  v  a2s .  c  o m
 * @param tranMap PlatformTransactionManager
 * @param statMap TransactionStatus
 * @param log Log
 * @return ???PlatformTransactionManager?????????true??
 */
public static boolean endTransactions(Map<?, ?> tranMap, Map<String, TransactionStatus> statMap, Log log) {
    boolean isNormal = true;

    Set<Entry<String, TransactionStatus>> statSet = statMap.entrySet();

    if (statSet == null || statSet.isEmpty()) {
        return isNormal;
    }

    Stack<Entry<String, TransactionStatus>> stack = new Stack<Entry<String, TransactionStatus>>();
    for (Entry<String, TransactionStatus> stat : statSet) {
        stack.push(stat);
    }

    while (!stack.isEmpty()) {
        // ???
        Entry<String, TransactionStatus> statEntry = stack.pop();
        String key = statEntry.getKey();
        TransactionStatus trnStat = statEntry.getValue();

        if (trnStat == null) {
            continue;
        }

        // ???
        Object ptmObj = tranMap.get(key);
        if (ptmObj == null || !(ptmObj instanceof PlatformTransactionManager)) {
            continue;
        }
        PlatformTransactionManager ptm = (PlatformTransactionManager) ptmObj;

        // ??????
        if (trnStat.isCompleted()) {
            continue;
        }

        if (log != null && log.isDebugEnabled()) {
            logDebug(log, LogId.DAL025041, trnStat);
        }

        // ?
        try {
            ptm.rollback(trnStat);
        } catch (TransactionException e) {
            if (log != null && log.isErrorEnabled()) {
                logError(log, LogId.EAL025045, e, key);
            }
            isNormal = false;
            // ????????
        }

        if (log != null && log.isDebugEnabled()) {
            logDebug(log, LogId.DAL025041, trnStat);
        }
    }
    return isNormal;
}

From source file:com.cisco.dvbu.ps.common.util.CommonUtils.java

public static void writeOutput(String message, String prefix, String options, Log logger, boolean debug1,
        boolean debug2, boolean debug3) {

    // Determine if there is a prefix to prepend
    if (prefix == null) {
        prefix = "";
    } else {/*from w  w w .  java2s  .  c  o m*/
        prefix = prefix + "::";
    }
    //Write out the log if not suppressed
    if (!options.contains("-suppress")) {

        //Write to log when -error
        if (options.contains("-error")) {
            if (logger.isErrorEnabled()) {
                logger.error(prefix + message);
            }
        }

        //Write to log when -info
        if (options.contains("-info")) {
            if (logger.isInfoEnabled()) {
                logger.info(prefix + message);
            }
        }

        //Write to log when -debug1
        if (options.contains("-debug1") && debug1) {
            // logger.isInfoEnabled() is checked on purpose.  Don't change it.
            if (logger.isInfoEnabled()) {
                logger.info("DEBUG1::" + prefix + message);
            }
        }

        //Write to log when -debug2
        if (options.contains("-debug2") && debug2) {
            // logger.isInfoEnabled() is checked on purpose.  Don't change it.
            if (logger.isInfoEnabled()) {
                logger.info("DEBUG2::" + prefix + message);
            }
        }

        //Write to log when -debug3
        if (options.contains("-debug3") && debug3) {
            // logger.isInfoEnabled() is checked on purpose.  Don't change it.
            if (logger.isInfoEnabled()) {
                logger.info("DEBUG3::" + prefix + message);
            }
        }
    }
}

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

public final static boolean error(final Log log) {
    return (log.isErrorEnabled());
}