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

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

Introduction

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

Prototype

void error(Object message);

Source Link

Document

Logs a message with error log level.

Usage

From source file:it.doqui.index.ecmengine.client.backoffice.EcmEngineBackofficeDelegateFactory.java

/**
 * Metodo factory che crea una nuova istanza del client delegate.
 * //ww  w .j  a va 2  s. c  om
 * <p>La factory cerca di istanziare la classe di implementazione
 * specificata dall'utente nel file di propriet&agrave;
 * {@code ecmengine-backoffice-delegate.properties}. Se tale operazione fallisce
 * la factory cerca di istanziare la classe di default definita
 * in {@link EcmEngineBackofficeDelegateConstants#ECMENGINE_BKO_DELEGATE_CLASS_NAME_DEFAULT}.
 * </p>
 * 
 * @return Una nuova istanza del client delegate.
 * 
 * @throws EcmEngineBackofficeDelegateInstantiationException Se si verifica un
 * errore nell'istanziazione del client delegate.
 */
public static EcmEngineBackofficeDelegate getEcmEngineBackofficeDelegate()
        throws EcmEngineBackofficeDelegateInstantiationException {
    final ResourceBundle resources = ResourceBundle.getBundle(ECMENGINE_BKO_PROPERTIES_FILE);
    final String caller = resources.getString(ECMENGINE_BKO_DELEGATE_CALLER);
    final Log logger = LogFactory.getLog(caller + ECMENGINE_BKO_DELEGATE_LOG_CATEGORY);
    final String implClass = resources.getString(ECMENGINE_BKO_DELEGATE_CLASS);

    logger.debug("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] BEGIN");

    EcmEngineBackofficeDelegate backofficeInstance = null;

    logger.debug("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] " + "Classe delegate: "
            + implClass);
    try {
        backofficeInstance = getClassInstance(implClass, logger);
    } catch (EcmEngineBackofficeDelegateInstantiationException e) {
        logger.warn("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] "
                + "Impossibile caricare la classe \"" + implClass + "\": " + e.getMessage());

        logger.debug("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] "
                + "Classe delegate di default: " + ECMENGINE_BKO_DELEGATE_CLASS_NAME_DEFAULT);
        try {
            backofficeInstance = getClassInstance(ECMENGINE_BKO_DELEGATE_CLASS_NAME_DEFAULT, logger);
        } catch (EcmEngineBackofficeDelegateInstantiationException ex) {
            logger.error("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] "
                    + "Impossibile caricare la classe di default \"" + ECMENGINE_BKO_DELEGATE_CLASS_NAME_DEFAULT
                    + "\": " + ex.getMessage());

            throw ex; // Rilancia l'eccezione al chiamante
        }

    } finally {
        logger.debug("[EcmEngineBackofficeDelegateFactory::getEcmEngineBackofficeDelegate] END");
    }

    return backofficeInstance;
}

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.
 *
 * @param  log     the log where the messages will go
 * @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
 *//* ww  w.  j  a  va2  s . com*/
public static Msg error(Log log, String key, Object... varargs) {
    if (log.isErrorEnabled()) {
        Msg msg = Msg.createMsg(key, varargs);
        log.error((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg);
        return msg;
    }

    return null;
}

From source file:com.wavemaker.runtime.data.util.JDBCUtils.java

public static Object runSql(String sql[], String url, String username, String password, String driverClassName,
        Log logger, boolean isDDL) {

    Connection con = getConnection(url, username, password, driverClassName);

    try {/*from w w w. j  a v  a 2  s  . c  om*/
        try {
            con.setAutoCommit(true);
        } catch (SQLException ex) {
            throw new DataServiceRuntimeException(ex);
        }

        Statement s = con.createStatement();

        try {
            try {
                for (String stmt : sql) {
                    if (logger != null && logger.isInfoEnabled()) {
                        logger.info("Running " + stmt);
                    }
                    s.execute(stmt);
                }
                if (!isDDL) {
                    ResultSet r = s.getResultSet();
                    List<Object> rtn = new ArrayList<Object>();
                    while (r.next()) {
                        // getting only the first col is pretty unuseful
                        rtn.add(r.getObject(1));
                    }
                    return rtn.toArray(new Object[rtn.size()]);
                }
            } catch (Exception ex) {
                if (logger != null && logger.isErrorEnabled()) {
                    logger.error(ex.getMessage());
                }
                throw ex;
            }
        } finally {
            try {
                s.close();
            } catch (Exception ignore) {
            }
        }
    } catch (Exception ex) {
        if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        } else {
            throw new DataServiceRuntimeException(ex);
        }
    } finally {
        try {
            con.close();
        } catch (Exception ignore) {
        }
    }

    return null;
}

From source file:eu.semaine.jms.JMSLogReader.java

@Override
public void onMessage(Message m) {
    try {// ww  w  . j a v  a  2  s  . c  om
        if (!(m instanceof TextMessage)) {
            return; // silently ignore
        }
        String dest = m.getJMSDestination().toString();
        // dest is expected to have the form
        // semaine.log.component.log-level
        String[] parts = dest.split("\\.");
        String level = parts[parts.length - 1].toLowerCase();
        String component = parts[parts.length - 2];
        Log log = LogFactory.getLog("semaine.log." + component);
        String text = ((TextMessage) m).getText();
        //text = time.format(new Date(m.getJMSTimestamp())) + " " + text;
        if (level.equals("info"))
            log.info(text);
        else if (level.equals("warn"))
            log.warn(text);
        else if (level.equals("error"))
            log.error(text);
        else if (level.equals("debug"))
            log.debug(text);
        else
            log.info(text);
    } catch (Exception e) {

    }
}

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.
 *
 * @param  log     the log where the messages will go
 * @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
 *//*from   w  w w. j  ava2  s  .c  om*/
public static Msg error(Log log, Locale locale, String key, Object... varargs) {
    if (log.isErrorEnabled()) {
        Msg msg = Msg.createMsg(locale, key, varargs);
        log.error((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg);
        return msg;
    }

    return null;
}

From source file:interactivespaces.launcher.bootstrap.Log4jLoggingProvider.java

@Override
public boolean modifyLogLevel(Log log, String level) {
    if (Log4JLogger.class.isAssignableFrom(log.getClass())) {

        Level l = LOG_4J_LEVELS.get(level.toLowerCase());
        if (l != null) {
            ((Log4JLogger) log).getLogger().setLevel(l);

            return true;
        } else {//from   www.  j  a  v  a2s . c o m
            log.error(String.format("Unknown log level %s", level));
        }
    } else {
        log.error("Attempt to modify an unmodifiable logger");
    }

    return false;
}

From source file:com.tecapro.inventory.common.util.LogUtil.java

/**
 * // ww w.  ja va 2s  .  c  om
 * Error log output
 * 
 * @param log
 * @param clazz
 * @param method
 * @param time
 */
public void errorLog(Log log, String clazz, String method, InfoValue info, Throwable e) {
    LOG_LEVEL.remove(Thread.currentThread());
    log.error(returnLogString(clazz, method, info, LogPrefix.OTHER, e));
    log.error(e.getMessage(), e);
}

From source file:com.tecapro.inventory.common.util.LogUtil.java

/**
 * /*from   w ww.  j  a v a 2  s .  c o m*/
 * Error log output
 * 
 * @param log
 * @param clazz
 * @param method
 * @param time
 */
public void errorLog(Log log, String clazz, String method, InfoValue pinfo, String message) {
    LOG_LEVEL.remove(Thread.currentThread());
    log.error(returnLogString(clazz, method, pinfo, LogPrefix.OTHER, message));
}

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.
 *
 * @param  log      the log where the messages will go
 * @param  basename the base name of the resource bundle
 * @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  ww  .  ja  v  a2 s  . c  om*/
public static Msg error(Log log, BundleBaseName basename, String key, Object... varargs) {
    if (log.isErrorEnabled()) {
        Msg msg = Msg.createMsg(basename, key, varargs);
        log.error((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg);
        return msg;
    }

    return null;
}

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.
 *
 * @param  log      the log where the messages will go
 * @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
 *//*from   www .  j  a v  a 2s .  c  om*/
public static Msg error(Log log, BundleBaseName basename, Locale locale, String key, Object... varargs) {
    if (log.isErrorEnabled()) {
        Msg msg = Msg.createMsg(basename, locale, key, varargs);
        log.error((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg);
        return msg;
    }

    return null;
}