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, Throwable t);

Source Link

Document

Logs an error with error log level.

Usage

From source file:org.displaytag.exception.BaseNestableJspTagException.java

/**
 * Instantiate a new BaseNestableJspTagException.
 * @param source Class where the exception is generated
 * @param message message//  w w  w .  jav  a 2  s  . c  o m
 * @param cause previous Exception
 */
public BaseNestableJspTagException(Class source, String message, Throwable cause) {
    super(message);
    this.sourceClass = source;
    this.nestedException = cause;

    // log exception
    Log log = LogFactory.getLog(source);

    // choose appropriate logging method
    if (getSeverity() == SeverityEnum.DEBUG) {
        log.debug(toString(), cause);
    } else if (getSeverity() == SeverityEnum.INFO) {
        log.info(toString(), cause);
    } else if (getSeverity() == SeverityEnum.WARN) {
        log.warn(toString(), cause);
    } else {
        // error - default
        log.error(toString(), cause);
    }

}

From source file:org.displaytag.exception.BaseNestableRuntimeException.java

/**
 * Instantiate a new BaseNestableRuntimeException.
 * @param source Class where the exception is generated
 * @param message message//from   ww  w .j a va  2  s. co  m
 * @param cause previous Exception
 */
public BaseNestableRuntimeException(Class source, String message, Throwable cause) {
    super(message);
    this.sourceClass = source;
    this.nestedException = cause;

    // log exception
    Log log = LogFactory.getLog(source);

    // choose appropriate logging method
    if (getSeverity() == SeverityEnum.DEBUG) {
        log.debug(toString(), cause);
    } else if (getSeverity() == SeverityEnum.INFO) {
        log.info(toString(), cause);
    } else if (getSeverity() == SeverityEnum.WARN) {
        log.warn(toString(), cause);
    } else {
        // error - default
        log.error(toString(), cause);
    }

}

From source file:org.easyrec.utils.spring.exception.aop.ThrowableToExceptionAspectAdvice.java

public Object mapToException(ProceedingJoinPoint pjp, MapThrowableToException mtte) throws Exception {

    try {/*w  w  w  .  ja  v  a2  s.c o  m*/
        return pjp.proceed();
    } catch (Throwable ta) {
        Log logger = LogFactory.getLog(pjp.getTarget().getClass());
        Constructor<? extends Exception> cons;
        Exception ex = null;
        LoggerUtils.log(logger, mtte.logLevel(), "Aspect caught Exception", ta);
        try {
            cons = mtte.exceptionClazz().getConstructor(String.class);
            ex = cons.newInstance((ta.getMessage()));
        } catch (NoSuchMethodException nsme) {
            logger.error("The exception passed to the aspect does not provide a constructor(String message)!",
                    nsme);
        } catch (Exception e) {
            logger.error("Error instantiating aspect Exception, throwing original instead", e);
            throw (Exception) ta;
        }
        throw ex;
    }
}

From source file:org.easyrec.utils.spring.log.LoggerUtils.java

/**
 * Writes the given 'message' to the Log 'logger' with level 'logLevel'.
 *
 * @param logger   the Log to which the message is written
 * @param logLevel the level to which the message is written
 * @param message  the message to be written
 * @param ta       a Throwable passed on to the Log
 *///  w  ww . ja v a 2s . c  om
public static void log(Log logger, String logLevel, String message, Throwable ta) {
    if (logLevel.equalsIgnoreCase("info")) {
        if (logger.isInfoEnabled()) {
            logger.info(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("debug")) {
        if (logger.isDebugEnabled()) {
            logger.debug(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("error")) {
        if (logger.isErrorEnabled()) {
            logger.error(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("trace")) {
        if (logger.isTraceEnabled()) {
            logger.trace(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("warn")) {
        if (logger.isWarnEnabled()) {
            logger.warn(message, ta);
        }
    } else if (logLevel.equalsIgnoreCase("fatal")) {
        if (logger.isFatalEnabled()) {
            logger.fatal(message, ta);
        }
    } else {
        logger.error("Passed unknown log level " + logLevel + " to Aspect - logging to error instead!");
        logger.error(message, ta);
    }
}

From source file:org.eclipse.smila.processing.pipelets.xmlprocessing.util.XPathUtils.java

/**
 * Queries for index field.//from  w ww .  jav a 2s  .c o  m
 * 
 * @param node
 *          the Node
 * @param xpath
 *          the XPath
 * @param namespaceNode
 *          the namespace
 * @param separator
 *          the seperator
 * @return a Object (String, Double, Boolean)
 */
public static Object queryForIndexField(Node node, String xpath, Node namespaceNode, String separator) {
    final Log log = LogFactory.getLog(XPathUtils.class);
    try {
        final XObject xobj = XPathAPI.eval(node, xpath, namespaceNode);

        if (xobj instanceof NodeSequence) {
            final NodeList nlTemp = xobj.nodelist();

            final StringBuffer sb = new StringBuffer("");
            for (int i = 0; i < nlTemp.getLength(); i++) {

                final XObject value = XPathAPI.eval(nlTemp.item(i), "string()");
                if ((i > 0) && (separator != null)) {
                    sb.append(separator);
                }
                sb.append(value.str());
            }
            return sb.toString();
        } else if (xobj instanceof XBoolean) {
            return Boolean.valueOf(xobj.bool());
        } else if (xobj instanceof XNumber) {
            return new Double(xobj.num());
        } else if (xobj instanceof XRTreeFrag) {
            return xobj.str();
        } else if (xobj instanceof XString) {
            return xobj.str();
        } else {
            throw new Exception("unsupported xpath return type [" + xobj.getClass().getName() + "]");
        }
    } catch (final Exception e) {
        log.error("unkown error occured", e);
        return null;
    }
}

From source file:org.eclipse.smila.processing.pipelets.xmlprocessing.util.XPathUtils.java

/**
 * Removes nodes by XPath./*from   w  ww .  ja v  a2s.c  o  m*/
 * 
 * @param node
 *          the Node
 * @param xpath
 *          the XPath
 * @param namespaceNode
 *          the namespace
 */
public static void removeNodesByXPath(Node node, String xpath, Node namespaceNode) {

    final Log log = LogFactory.getLog(XPathUtils.class);

    try {

        final XObject xobj = XPathAPI.eval(node, xpath, namespaceNode);

        if (xobj instanceof NodeSequence) {
            final NodeList nlTemp = xobj.nodelist();

            for (int i = 0; i < nlTemp.getLength(); i++) {
                final Node parent = nlTemp.item(i).getParentNode();
                parent.removeChild(nlTemp.item(i));
            }
            /*
             * } else if (xobj instanceof XBoolean) { xobj.nodelist() return new Boolean(xobj.bool()); } else if (xobj
             * instanceof XNumber) { return new Double(xobj.num()); } else if (xobj instanceof XRTreeFrag) { return
             * xobj.str(); } else if (xobj instanceof XString) { return xobj.str();
             */
        } else {
            throw new Exception("unsupported xpath return type [" + xobj.getClass().getName() + "]");
        }
    } catch (final Exception e) {
        log.error("unkown error occured", e);
    }
}

From source file:org.eclipse.smila.search.datadictionary.DataDictionaryAccess.java

/**
 * Parse configuration and return according IRMType.
 * //  w w w  .ja  va2  s. co m
 * @param configurationElement
 *          Configuration element.
 * @param ordinal
 *          Ordinal.
 * @return Type name.
 */
public static String parseType(IConfigurationElement configurationElement, int ordinal) {

    if (!configurationElement.getName().equals("DataDictionaryAccess")) {
        return null;
    }

    final Log log = LogFactory.getLog(DataDictionaryAccess.class);

    try {
        String name = configurationElement.getAttribute("Clazz");
        if (name == null) {
            name = "[missing attribute name]";
        }
        return name;
    } catch (final Exception e) {
        String name = configurationElement.getAttribute("Clazz");
        if (name == null) {
            name = "[missing attribute name]";
        }
        final String msg = "Failed to load StrategyType named " + name + " in "
                + configurationElement.getDeclaringExtension().getNamespaceIdentifier();
        if (log.isErrorEnabled()) {
            log.error(msg, e);
        }
        return null;
    }
}

From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java

/**
 * This method adds an index entry to the data dictionary and saves it.
 * /*from   w w w .j  a va2s.  c om*/
 * @param dIndex
 *          the d index
 * 
 * @throws DataDictionaryException
 *           the data dictionary exception
 */
public static void addIndex(final DIndex dIndex) throws DataDictionaryException {
    final Log log = LogFactory.getLog(DataDictionaryController.class);
    synchronized (mutex) {
        ensureLoaded();
        if (hasIndexIgnoreCase(dIndex.getName())) {
            throw new DataDictionaryException(
                    "index already exists in data dictionary [" + getExistingIndexName(dIndex.getName()) + "]");
        }

        final DConfiguration dConfig = dIndex.getConfiguration();
        if (dConfig != null) {
            validateConfiguration(dConfig, dIndex.getIndexStructure());
        }

        dd.addIndex(dIndex);

        // validate data dictionary
        try {
            final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
            XMLUtils.stream(doc.getDocumentElement(), true, "UTF-8", new ByteArrayOutputStream());
        } catch (final DDException e) {
            log.error("unable to save data dictionary", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary");
        } catch (final XMLUtilsException e) {
            log.error("Unable to stream DataDictionary!", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary while streaming");
        }

        save();
    }
}

From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java

/**
 * Rename index.//  w  w  w .jav a 2s .  co m
 * 
 * @param indexName
 *          the index name
 * @param newIndexName
 *          the new index name
 * 
 * @return true, if successful
 * 
 * @throws DataDictionaryException
 *           the data dictionary exception
 */
public static boolean renameIndex(final String indexName, final String newIndexName)
        throws DataDictionaryException {
    final Log log = LogFactory.getLog(DataDictionaryController.class);

    synchronized (mutex) {
        ensureLoaded();
        if (dd.getIndex(newIndexName) != null) {
            throw new DataDictionaryException(
                    String.format("Cannot rename index to [%s] because it's already exists!", newIndexName));
        }
        log.debug("Updating datadictionary...");
        final DIndex index = dd.getIndex(indexName);
        if (index == null) {
            return false; // no index entry
        }
        dd.removeIndex(index);
        index.setName(newIndexName);
        final DIndexStructure indexStructure = index.getIndexStructure();
        if (indexStructure != null) {
            indexStructure.setName(newIndexName);
        }
        dd.addIndex(index);
        // validate data dictionary
        try {
            final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
            XMLUtils.stream(doc.getDocumentElement(), true, "UTF-8", new ByteArrayOutputStream());
        } catch (final DDException e) {
            log.error("unable to save data dictionary", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary");
        } catch (final XMLUtilsException e) {
            log.error("Unable to stream DataDictionary!", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary while streaming");
        }

        save();
        return true;
    }

}

From source file:org.eclipse.smila.search.datadictionary.DataDictionaryController.java

/**
 * This method removes an index entry from the data dictionary. It returnes true, when the index entry has exists.
 * /*from   ww w . j a va2s. co  m*/
 * @param indexName
 *          the index name
 * 
 * @return true, if delete index
 * 
 * @throws DataDictionaryException
 *           the data dictionary exception
 */
public static boolean deleteIndex(final String indexName) throws DataDictionaryException {
    final Log log = LogFactory.getLog(DataDictionaryController.class);

    synchronized (mutex) {
        ensureLoaded();
        log.debug("Updating datadictionary...");
        final DIndex index = dd.getIndex(indexName);
        if (index == null) {
            return false; // no index entry
        }
        dd.removeIndex(index);

        // validate data dictionary
        try {
            final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
            XMLUtils.stream(doc.getDocumentElement(), true, "UTF-8", new ByteArrayOutputStream());
        } catch (final DDException e) {
            log.error("unable to save data dictionary", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary");
        } catch (final XMLUtilsException e) {
            log.error("Unable to stream DataDictionary!", e);
            try {
                final Document doc = DAnyFinderDataDictionaryCodec.encode(dd);
                log.debug("invalid data dictionary\n"
                        + new String(XMLUtils.stream(doc.getDocumentElement(), false)));

            } catch (final Throwable ex) {
                ; // do nothing
            }
            throw new DataDictionaryException("invalid data dictionary while streaming");
        }

        save();
        return true;
    }
}