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:org.displaytag.exception.BaseNestableJspTagException.java

/**
 * Instantiate a new BaseNestableJspTagException.
 * @param source Class where the exception is generated
 * @param message message/*from   w w  w  .  j ava 2 s.c  o  m*/
 */
public BaseNestableJspTagException(Class source, String message) {
    super(message);
    this.sourceClass = source;

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

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

}

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

/**
 * Instantiate a new BaseNestableRuntimeException.
 * @param source Class where the exception is generated
 * @param message message//from  w  w w . ja va  2 s . c o m
 */
public BaseNestableRuntimeException(Class source, String message) {
    super(message);
    this.sourceClass = source;

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

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

}

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
 *///from www. j a  v a 2 s. com
public static void log(Log logger, String logLevel, String message) {
    if (logLevel.equalsIgnoreCase("info")) {
        if (logger.isInfoEnabled()) {
            logger.info(message);
        }
    } else if (logLevel.equalsIgnoreCase("debug")) {
        if (logger.isDebugEnabled()) {
            logger.debug(message);
        }
    } else if (logLevel.equalsIgnoreCase("error")) {
        if (logger.isErrorEnabled()) {
            logger.error(message);
        }
    } else if (logLevel.equalsIgnoreCase("trace")) {
        if (logger.isTraceEnabled()) {
            logger.trace(message);
        }
    } else if (logLevel.equalsIgnoreCase("warn")) {
        if (logger.isWarnEnabled()) {
            logger.warn(message);
        }
    } else if (logLevel.equalsIgnoreCase("fatal")) {
        if (logger.isFatalEnabled()) {
            logger.fatal(message);
        }
    } else {
        logger.error("Passed unknown log level " + logLevel + " to Aspect - logging to error instead!");
        logger.error(message);
    }
}

From source file:org.eclipse.emf.mwe.core.WorkflowEngine.java

private void logIssues(final Log logger, final Issues issues) {
    // log any configuration warning messages
    final Diagnostic[] issueArray = issues.getIssues();
    for (final Diagnostic issue : issueArray) {
        if (issue.getSeverity() == Diagnostic.ERROR) {
            logger.error(issue.toString());
        }//from  w w w . j  a  v a 2 s  . c om
        if (issue.getSeverity() == Diagnostic.WARNING) {
            logger.warn(issue.toString());
        }
        if (issue.getSeverity() == Diagnostic.INFO) {
            logger.info(issue.toString());
        }
    }
}

From source file:org.eclipse.emf.teneo.eclipse.StoreEclipseUtil.java

/** Utility method to handle an error */
public static void handleError(Throwable t, Log log) {
    t.printStackTrace(System.err);
    log.error(t);
    MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error Occured",
            t.getMessage());//from   www.java 2 s . com
}

From source file:org.eclipse.smila.connectivity.framework.schema.ConfigurationLoader.java

/**
 * Unmarshall index order configuration.
 * /*from  www . ja  va 2s  . c om*/
 * @param is
 *          xml input stream
 * 
 * @return index order configuration
 * 
 * @throws JAXBException
 *           the JAXB exception
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 * @throws SchemaNotFoundException
 *           the index order schema not found exception
 */
public static DataSourceConnectionConfig unmarshall(final InputStream is)
        throws JAXBException, IOException, SchemaNotFoundException {
    final Log log = LogFactory.getLog(ConfigurationLoader.class);
    if (is == null) {
        throw new SchemaRuntimeException("Configaration stream is null!");
    }
    InputStream inputStream = null;
    try {
        java.io.ByteArrayOutputStream bos = new ByteArrayOutputStream();
        IOUtils.copy(is, bos);
        final byte[] array = bos.toByteArray();
        bos = null;
        inputStream = new ByteArrayInputStream(array);
        // preinit context
        JaxbThreadContext.setPluginContext(Thread.currentThread(), null);
        // unmarshall first time to locate plug-in
        final JAXBContext jaxbContext = newSimpleContext();
        jaxbContext.createUnmarshaller().unmarshal(inputStream);
        IOUtils.closeQuietly(inputStream);

        final JaxbPluginContext pluginContext = JaxbThreadContext.getPluginContext(Thread.currentThread());
        final Unmarshaller finalUnmarshaller = pluginContext.createValidatingUnmarshaller();
        inputStream = new ByteArrayInputStream(array);
        // unmarshall second time by plug-in
        return (DataSourceConnectionConfig) finalUnmarshaller.unmarshal(inputStream);
    } catch (final SchemaNotFoundException e) {
        if (log.isErrorEnabled()) {
            log.error(e);
        }
        throw e;
    } finally {
        JaxbThreadContext.removeKey(Thread.currentThread());
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(inputStream);
    }

}

From source file:org.eclipse.smila.lucene.internal.LuceneSchemaResolver.java

/**
 * {@inheritDoc}/*from   w ww .j a  v  a2  s  .  co m*/
 * 
 * @see org.eclipse.smila.utils.xml.SchemaResolver#getSchemaByName(java.lang.String)
 */
@Override
public byte[] getSchemaByName(final String schemaName) {

    final Log log = LogFactory.getLog(getClass());

    final Set<String> schemas = new HashSet<String>();
    for (final String schema : KNOWN_SCHEMAS) {
        schemas.add("../xml/" + schema);
    }

    if (!schemas.contains(schemaName)) {
        // not responsible for schema loading.
        return null;
    }

    final File folder = ConfigUtils.getConfigFolder(LuceneService.BUNDLE_NAME, "xml");
    if (folder == null) {
        if (log.isErrorEnabled()) {
            log.error("unable to locate configuration folder [" + LuceneService.BUNDLE_NAME + "/xml]");
        }
        return null;
    }

    FileInputStream fis = null;
    final String fileName = folder.getPath() + "/" + schemaName;
    try {
        fis = new FileInputStream(fileName);
        final byte[] schema = IOUtils.toByteArray(fis);
        return schema;
    } catch (final Exception exception) {
        if (log.isErrorEnabled()) {
            log.error("unable to read schema file [" + fileName + "]", exception);
        }
        return null;
    } finally {
        IOUtils.closeQuietly(fis);
    }
}

From source file:org.eclipse.smila.management.jmx.client.helpers.ConfigLoader.java

/**
 * Creates the validation event handler.
 * /* w w  w .  j  a  v  a 2  s . c  o m*/
 * @return the validation event handler
 */
public static ValidationEventHandler createValidationEventHandler() {
    return new ValidationEventHandler() {
        public boolean handleEvent(final ValidationEvent ve) {
            final Log log = LogFactory.getLog(Main.class);
            if (ve.getSeverity() != ValidationEvent.WARNING) {
                final ValidationEventLocator vel = ve.getLocator();
                if (log.isErrorEnabled()) {
                    log.error("Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + "]:"
                            + ve.getMessage());
                }
                return false;
            }
            return true;
        }
    };
}

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

/**
 * A 32 byte GUID generator (Globally Unique ID). These artificial keys SHOULD <strong>NOT </strong> be seen by the
 * user, not even touched by the DBA but with very rare exceptions, just manipulated by the database and the programs.
 * /*from www  . j  a  v  a 2 s  . co  m*/
 * Usage: Add an id field (type java.lang.String) to your EJB, and add setId(XXXUtil.generateGUID(this)); to the
 * ejbCreate method.
 * 
 * @param o
 *          a Object
 * @return a String
 */
public static final String generateGUID(Object o) {
    final Log log = LogFactory.getLog(XMLUtils.class);
    final StringBuffer tmpBuffer = new StringBuffer(16);
    if (s_hexServerIP == null) {
        java.net.InetAddress localInetAddress = null;
        try {
            // get the inet address
            localInetAddress = java.net.InetAddress.getLocalHost();
        } catch (java.net.UnknownHostException uhe) {
            // todo: find better way to get around this...
            final String msg = "ConfigurationUtil: Could not get the local IP address using InetAddress.getLocalHost()!";
            System.err.println(msg);
            if (log.isErrorEnabled()) {
                log.error(uhe);
            }
            return null;
        }
        final byte[] serverIP = localInetAddress.getAddress();
        s_hexServerIP = hexFormat(getInt(serverIP), 8);
    }
    final String hashcode = hexFormat(System.identityHashCode(o), 8);
    tmpBuffer.append(s_hexServerIP);
    tmpBuffer.append(hashcode);

    final long timeNow = System.currentTimeMillis();
    final int timeLow = (int) timeNow & 0xFFFFFFFF;
    final int node = SEEDER.nextInt();

    final StringBuffer guid = new StringBuffer(32);
    guid.append(hexFormat(timeLow, 8));
    guid.append(tmpBuffer.toString());
    guid.append(hexFormat(node, 8));
    return guid.toString();
}

From source file:org.eclipse.smila.search.CoreSchemaResolver.java

/**
 * {@inheritDoc}/*w w w  . j  a  v  a 2 s  . com*/
 * 
 * @see org.eclipse.smila.utils.xml.SchemaResolver#getSchemaByName(java.lang.String)
 */
public byte[] getSchemaByName(final String schemaName) {

    final Log log = LogFactory.getLog(getClass());

    final Set<String> schemas = new HashSet<String>();
    for (final String schema : KNOWN_SCHEMAS) {
        schemas.add("../xml/" + schema);
    }

    if (!schemas.contains(schemaName)) {
        // not responsible for schema loading.
        return null;
    }

    final File folder = ConfigUtils.getConfigFolder(EIFActivator.BUNDLE_NAME, "xml");
    if (folder == null) {
        if (log.isErrorEnabled()) {
            log.error("unable to locate configuration folder [" + EIFActivator.BUNDLE_NAME + "/xml]");
        }
        return null;
    }

    FileInputStream fis = null;
    final String fileName = folder.getPath() + "/" + schemaName;
    try {
        fis = new FileInputStream(fileName);
        final byte[] schema = IOUtils.toByteArray(fis);
        return schema;
    } catch (final Exception exception) {
        if (log.isErrorEnabled()) {
            log.error("unable to read schema file [" + fileName + "]", exception);
        }
        return null;
    } finally {
        IOUtils.closeQuietly(fis);
    }
}