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.jasig.portal.spring.PortalApplicationContextLocator.java

/**
 * If the ApplicationContext returned by {@link #getApplicationContext()} is 'portal managed' the shutdown hook
 * for the context is called, closing and cleaning up all spring managed resources.
 *
 * If the ApplicationContext returned by {@link #getApplicationContext()} is actually a WebApplicationContext
 * this method does nothing but log an error message.
 *///from  w  w w  .ja v a  2s  . co  m
public static void shutdown() {
    Log logger = LogFactory.getLog(LOGGER_NAME);

    if (applicationContextCreator.isCreated()) {
        final ConfigurableApplicationContext applicationContext = applicationContextCreator.get();
        applicationContext.close();
    } else {
        final IllegalStateException createException = new IllegalStateException(
                "No portal managed ApplicationContext has been created, there is nothing to shutdown.");
        logger.error(createException, createException);
    }
}

From source file:org.jasig.springframework.web.portlet.context.PortletContextLoader.java

/**
 * Initialize Spring's portlet application context for the given portlet context,
 * using the application context provided at construction time, or creating a new one
 * according to the "{@link #CONTEXT_CLASS_PARAM contextClass}" and
 * "{@link #CONFIG_LOCATION_PARAM contextConfigLocation}" context-params.
 * @param portletContext current portlet context
 * @return the new PortletApplicationContext
 * @see #CONTEXT_CLASS_PARAM//from  www  .  ja  v a 2  s  .co m
 * @see #CONFIG_LOCATION_PARAM
 */
public PortletApplicationContext initWebApplicationContext(PortletContext portletContext) {
    if (portletContext
            .getAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
        throw new IllegalStateException(
                "Cannot initialize context because there is already a root portlet application context present - "
                        + "check whether you have multiple PortletContextLoader* definitions in your portlet.xml!");
    }

    Log logger = LogFactory.getLog(PortletContextLoader.class);
    portletContext.log("Initializing Spring root PortletApplicationContext");
    if (logger.isInfoEnabled()) {
        logger.info("Root portlet PortletApplicationContext: initialization started");
    }
    long startTime = System.nanoTime();

    try {
        // Store context in local instance variable, to guarantee that
        // it is available on PortletContext shutdown.
        if (this.context == null) {
            this.context = createPortletApplicationContext(portletContext);
        }
        if (this.context instanceof ConfigurablePortletApplicationContext) {
            configureAndRefreshPortletApplicationContext((ConfigurablePortletApplicationContext) this.context,
                    portletContext);
        }
        portletContext.setAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE,
                this.context);

        ClassLoader ccl = Thread.currentThread().getContextClassLoader();
        if (ccl == PortletContextLoader.class.getClassLoader()) {
            currentContext = this.context;
        } else if (ccl != null) {
            currentContextPerThread.put(ccl, this.context);
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Published root PortletApplicationContext as PortletContext attribute with name ["
                    + PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE + "]");
        }
        if (logger.isInfoEnabled()) {
            long elapsedTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
            logger.info("Root PortletApplicationContext: initialization completed in " + elapsedTime + " ms");
        }

        return this.context;
    } catch (RuntimeException ex) {
        logger.error("Portlet context initialization failed", ex);
        portletContext.setAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE, ex);
        throw ex;
    } catch (Error err) {
        logger.error("Portlet context initialization failed", err);
        portletContext.setAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE, err);
        throw err;
    }
}

From source file:org.java.plugin.ObjectFactory.java

private static ExtendedProperties loadProperties(final ClassLoader cl) {
    Log log = LogFactory.getLog(ObjectFactory.class);
    File file = new File(System.getProperty("java.home") //$NON-NLS-1$
            + File.separator + "lib" + File.separator //$NON-NLS-1$
            + "jpf.properties"); //$NON-NLS-1$
    URL url = null;//ww w . java 2 s  .  c om
    if (file.canRead()) {
        try {
            url = IoUtil.file2url(file);
        } catch (MalformedURLException mue) {
            log.error("failed converting file " + file //$NON-NLS-1$
                    + " to URL", mue); //$NON-NLS-1$
        }
    }
    if (url == null) {
        if (cl != null) {
            url = cl.getResource("jpf.properties"); //$NON-NLS-1$
            if (url == null) {
                url = ClassLoader.getSystemResource("jpf.properties"); //$NON-NLS-1$
            }
        } else {
            url = ClassLoader.getSystemResource("jpf.properties"); //$NON-NLS-1$
        }
        if (url == null) {
            log.debug("no jpf.properties file found in ${java.home}/lib (" //$NON-NLS-1$
                    + file + ") nor in CLASSPATH, using standard properties"); //$NON-NLS-1$
            url = StandardObjectFactory.class.getResource("jpf.properties"); //$NON-NLS-1$
        }
    }
    try {
        InputStream strm = IoUtil.getResourceInputStream(url);
        try {
            ExtendedProperties props = new ExtendedProperties();
            props.load(strm);
            log.debug("loaded jpf.properties from " + url); //$NON-NLS-1$
            return props;
        } finally {
            try {
                strm.close();
            } catch (IOException ioe) {
                // ignore
            }
        }
    } catch (Exception e) {
        log.error("failed loading jpf.properties from CLASSPATH", //$NON-NLS-1$
                e);
    }
    return null;
}

From source file:org.jboss.netty.logging.CommonsLoggerTest.java

@Test
public void testErrorWithException() {
    org.apache.commons.logging.Log mock = createStrictMock(org.apache.commons.logging.Log.class);

    mock.error("a", e);
    replay(mock);/*from w  w w .  ja  v  a2 s . c o  m*/

    InternalLogger logger = new CommonsLogger(mock, "foo");
    logger.error("a", e);
    verify(mock);
}

From source file:org.jkcsoft.java.util.OsHelper.java

public static void runOsCommand(String command, Log log) throws IOException {
    try {/*  w ww. jav a 2s  .  c o  m*/

        Runtime rt = Runtime.getRuntime();
        Process p = rt.exec(command);

        BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

        BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

        // read the output from the command

        log.info("Here is the standard output of the command:");
        String stLine = null;
        while ((stLine = stdInput.readLine()) != null) {
            log.info(stLine);
        }

        // read any errors from the attempted command
        log.info("Here is the standard error of the command (if any):");
        while ((stLine = stdError.readLine()) != null) {
            log.info(stLine);
        }
    } catch (IOException e) {
        log.error("running OS command", e);
        throw e;
    }
}

From source file:org.jkcsoft.java.util.OsHelper.java

public static boolean isExecutable(File file, Log log) throws Exception {
    boolean is = true;

    if (isLinux()) {
        // e.g., /usr/bin/test -x /home/coles/build/build-tsess.sh && echo yes || echo no
        try {//from   ww w  .  j a  v  a  2 s  .c  om

            Runtime rt = Runtime.getRuntime();
            String stTest = "/usr/bin/test -x " + file.getAbsolutePath() + " && echo yes || echo no";
            log.debug("Command=" + stTest);

            Process p = rt.exec(stTest);

            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

            BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

            String stLine = null;

            // read any errors from the attempted command
            log.info("Here is the standard error of the command (if any):");
            while ((stLine = stdError.readLine()) != null) {
                log.warn(stLine);
            }

            // read the output from the command
            StringBuilder sbResponse = new StringBuilder();
            while ((stLine = stdInput.readLine()) != null) {
                sbResponse.append(stLine);
            }

            is = "yes".equalsIgnoreCase(sbResponse.toString());

        } catch (IOException e) {
            log.error("In isExecutable()", e);
            throw e;
        }
    } else {
        log.info("Not Linux -- assume executable");
    }

    return is;
}

From source file:org.kuali.coeus.sys.framework.controller.interceptor.PerformanceMeasurementFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    final long startTime = System.currentTimeMillis();
    PerformanceFilterResponse filterResponse = new PerformanceFilterResponse((HttpServletResponse) response);
    chain.doFilter(request, filterResponse);
    try {//from ww  w  .j  a  v a  2 s  .c  o  m
        processResponse(request, filterResponse, startTime);
    } catch (Throwable t) {
        Log logger = LogFactory.getLog(PerformanceMeasurementFilter.class);
        logger.error(t.getMessage(), t);
    }
}

From source file:org.latticesoft.util.common.LogUtil.java

public static void log(int level, Object o, Throwable t, Log log) {
    if (level == LogUtil.DEBUG)
        log.debug(o, t);/*  w ww  .j a v  a2s.  c o m*/
    else if (level == LogUtil.ERROR)
        log.error(o, t);
    else if (level == LogUtil.FATAL)
        log.fatal(o, t);
    else if (level == LogUtil.INFO)
        log.info(o, t);
    else if (level == LogUtil.TRACE)
        log.trace(o, t);
    else if (level == LogUtil.WARNING)
        log.warn(o, t);
}

From source file:org.opencms.repository.CmsRepositoryManager.java

/**
 * Creates a list of resource wrappers from a collection of configuration parameters, for use in configuring repositories.<p>
 *
 * @param config the configuration/* w ww.j  av  a2s  .c  o m*/
 * @param paramName the parameter name
 * @param log the logger to use for error messages
 *
 * @return the list of resource wrappers
 *
 * @throws CmsConfigurationException if something goes wrong with reading the configuration
 */
public static List<I_CmsResourceWrapper> createResourceWrappersFromConfiguration(
        CmsParameterConfiguration config, String paramName, Log log) throws CmsConfigurationException {

    List<I_CmsResourceWrapper> wrapperObjects = Lists.newArrayList();
    if (config.containsKey(paramName)) {
        List<String> wrappers = config.getList(paramName);
        for (String wrapperString : wrappers) {
            wrapperString = wrapperString.trim();
            String className;
            String configString = null;
            int separatorPos = wrapperString.indexOf(WRAPPER_CONFIG_SEPARATOR);
            if (separatorPos < 0) {
                className = wrapperString;
            } else {
                className = wrapperString.substring(0, separatorPos);
                configString = wrapperString.substring(separatorPos + 1);
            }

            Class<?> nameClazz;

            // init class for wrapper
            try {
                nameClazz = Class.forName(className);
            } catch (ClassNotFoundException e) {
                log.error(Messages.get().getBundle().key(Messages.LOG_WRAPPER_CLASS_NOT_FOUND_1, className), e);
                wrapperObjects.clear();
                break;
            }

            I_CmsResourceWrapper wrapper;
            try {
                wrapper = (I_CmsResourceWrapper) nameClazz.newInstance();
                if (configString != null) {
                    wrapper.configure(configString);
                }
            } catch (InstantiationException e) {
                throw new CmsConfigurationException(
                        Messages.get().container(Messages.ERR_INVALID_WRAPPER_NAME_1, wrapperString));
            } catch (IllegalAccessException e) {
                throw new CmsConfigurationException(
                        Messages.get().container(Messages.ERR_INVALID_WRAPPER_NAME_1, wrapperString));
            } catch (ClassCastException e) {
                throw new CmsConfigurationException(
                        Messages.get().container(Messages.ERR_INVALID_WRAPPER_NAME_1, wrapperString));
            }

            wrapperObjects.add(wrapper);

            if (CmsLog.INIT.isInfoEnabled()) {
                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ADD_WRAPPER_1,
                        wrapper.getClass().getName()));
            }
        }
    }
    return wrapperObjects;
}

From source file:org.openmrs.module.chica.web.ServletUtil.java

/**
 * Utility method for logging messages to a physical log as well as formatting the message for display to a user 
 * using HTML./*from  w  ww .  jav a 2s . c o  m*/
 * 
 * @param pw Printer used to write the HTML version.  This can be null if there's no intention for an HTML version
 * of the message.
 * @param e An exception to be logged.  This can be null if the exception logging is not needed.
 * @param log Log object used to write the message to disk.  This can be null if there's no intention to write the 
 * message to disk.
 * @param errorMessageParts The pieces used to build the log messages.
 * @return The HTML formatted message
 */
public static String writeHtmlErrorMessage(PrintWriter pw, Exception e, Log log, String... errorMessageParts) {
    if (errorMessageParts == null || errorMessageParts.length == 0) {
        return ChirdlUtilConstants.GENERAL_INFO_EMPTY_STRING;
    }

    StringBuffer htmlMessageBuffer = new StringBuffer("<b>");
    StringBuffer messageBuffer = new StringBuffer();
    for (String errorMessagePart : errorMessageParts) {
        htmlMessageBuffer.append("<p>");
        htmlMessageBuffer.append(errorMessagePart);
        htmlMessageBuffer.append("</p>");
        messageBuffer.append(errorMessagePart);
        messageBuffer.append(" ");
    }

    if (log != null) {
        if (e != null) {
            log.error(messageBuffer.toString(), e);
        } else {
            log.error(messageBuffer.toString());
        }
    }

    htmlMessageBuffer.append("</b>");
    if (pw != null) {
        pw.write(htmlMessageBuffer.toString());
    }

    return htmlMessageBuffer.toString();
}