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

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

Introduction

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

Prototype

boolean isWarnEnabled();

Source Link

Document

Is warn logging currently enabled?

Usage

From source file:rocket.logging.server.CommonsLoggingService.java

@Override
protected Logger createLoggerAdapter(final String loggerName) {
    final Log log = LogFactory.getLog(loggerName);
    return new Logger() {
        public void debug(final String message) {
            log.debug(message);/*  w w w.  jav a  2s.com*/
        }

        public void debug(final String message, final Throwable throwable) {
            log.debug(message, throwable);
        }

        public void info(final String message) {
            log.info(message);
        }

        public void info(final String message, final Throwable throwable) {
            log.info(message, throwable);
        }

        public void warn(final String message) {
            log.warn(message);
        }

        public void warn(final String message, final Throwable throwable) {
            log.warn(message, throwable);
        }

        public void error(final String message) {
            log.error(message);
        }

        public void error(final String message, final Throwable throwable) {
            log.error(message, throwable);
        }

        public void fatal(final String message) {
            log.fatal(message);
        }

        public void fatal(final String message, final Throwable throwable) {
            log.fatal(message, throwable);
        }

        public boolean isDebugEnabled() {
            return log.isDebugEnabled();
        }

        public boolean isInfoEnabled() {
            return log.isInfoEnabled();
        }

        public boolean isWarnEnabled() {
            return log.isWarnEnabled();
        }

        public boolean isErrorEnabled() {
            return log.isErrorEnabled();
        }

        public boolean isFatalEnabled() {
            return log.isFatalEnabled();
        }
    };
}

From source file:uk.ac.sanger.cgp.dbcon.util.InputOutputUtils.java

/**
 * Used instead of IOUtils closeQuietly since they do not log problems
 * to a log instance. This version will do if any exception occurs
 * /*from   ww  w  .  j a v a  2 s . co m*/
 * @param inputStream
 */
public static void closeQuietly(InputStream inputStream) {
    try {
        if (inputStream != null) {
            inputStream.close();
        }
    } catch (IOException e) {
        Log log = getLog();
        if (log.isWarnEnabled()) {
            log.warn("Could not close the given inputstream", e);
        }
    }
}

From source file:uk.ac.sanger.cgp.dbcon.util.ReaderUtils.java

/**
 * For the given resource this method will return a String which is the local
 * representation of the String input from the resource. Now delagates to
 * the {@link ResourceBuilder} object for the input stream
 * //from  w  ww.j a v  a2s  . c o  m
 * @param resource
 *          The resource which must be one of the following forms:
 *          <ul>
 *          <li>file: (for files)</li>
 *          <li>http:// (http)</li>
 *          <li>/ (classpath)</li>
 *          </ul>
 * @return The reader which underneath is a StringReader object. Will be null
 *         if it could not retrieve one
 */
public static Reader returnReaderFromResource(final String resource) {

    InputStream mainStream = null;
    Reader output = null;

    Log log = getLog();

    try {
        Resource resourceObj = ResourceBuilder.getResource(resource);
        mainStream = resourceObj.getInputStream();
        String streamContent = IOUtils.toString(mainStream);
        output = new StringReader(streamContent);
    } catch (DbConException e) {
        if (log.isWarnEnabled()) {
            log.warn("No valid stream could be generated for resource " + resource, e);
        }
    } catch (IOException e) {
        if (log.isWarnEnabled()) {
            log.warn("Error occured whilst converting InputStream to StringReader for resource " + resource, e);
        }
    } finally {
        InputOutputUtils.closeQuietly(mainStream);
    }

    return output;
}

From source file:xdoclet.modules.ojb.LogHelper.java

/**
 * Logs the given warning to stdout and to the log for the given class
 * (if the log level has been set to warn or higher).
 * //from w  w w .  j a v a  2  s.  co m
 * @param alsoStdout Whether to also put the message to stdout
 * @param clazz      The clazz
 * @param posInfo    The position info, e.g. method name
 * @param msg        The message
 */
public static void warn(boolean alsoStdout, Class clazz, String posInfo, Object msg) {
    if (alsoStdout) {
        System.out.println("Warning: " + msg.toString());
    }

    String name = clazz.getName();

    if (posInfo != null) {
        name += "." + posInfo;
    }

    Log log = LogFactory.getLog(name);

    if (log.isWarnEnabled()) {
        log.warn(msg);
    }
}