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

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

Introduction

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

Prototype

boolean isDebugEnabled();

Source Link

Document

Is debug logging currently enabled?

Usage

From source file:net.sf.nmedit.jtheme.component.misc.CallDescriptor.java

private Method getMethod(JTComponent target) {
    if (tmethod == null) {
        try {/*from   w w w  . ja  v  a  2 s. com*/
            tmethod = target.getClass().getDeclaredMethod(method, new Class[0]);
        } catch (Exception e) {
            Log l = LogFactory.getLog(getClass());
            if (l.isDebugEnabled())
                l.debug("Method not found: " + method, e);
        }
    }
    return tmethod;
}

From source file:com.github.lpezet.antiope.metrics.aws.spi.MetricTransformerFactory.java

/**
 * @param pFqcn fully qualified class name.
 *///  w  ww .  j  a v  a2  s .  co m
private IMetricTransformer loadRequestMetricTransformer(String pFqcn) {
    Log log = LogFactory.getLog(MetricTransformerFactory.class);
    if (log.isDebugEnabled()) {
        log.debug("Loading " + pFqcn);
    }
    try {
        Class<?> c = Class.forName(pFqcn);
        return (IMetricTransformer) c.newInstance();
    } catch (Throwable e) {
        if (log.isDebugEnabled()) {
            log.debug("Failed to load " + pFqcn + "; therefore ignoring " + this.name()
                    + " specific predefined metrics", e);
        }
    }
    return IMetricTransformer.NONE;
}

From source file:com.amazonaws.metrics.internal.cloudwatch.spi.AWSMetricTransformerFactory.java

/**
 * @param fqcn fully qualified class name.
 *//*from  w  ww .j a va  2s.  c o m*/
private RequestMetricTransformer loadRequestMetricTransformer(String fqcn) {
    Log log = LogFactory.getLog(AWSMetricTransformerFactory.class);
    if (log.isDebugEnabled()) {
        log.debug("Loading " + fqcn);
    }
    try {
        Class<?> c = Class.forName(fqcn);
        return (RequestMetricTransformer) c.newInstance();
    } catch (Throwable e) {
        if (log.isDebugEnabled()) {
            log.debug("Failed to load " + fqcn + "; therefore ignoring " + this.name()
                    + " specific predefined metrics", e);
        }
    }
    return RequestMetricTransformer.NONE;
}

From source file:edu.cornell.med.icb.goby.util.WarningCounter.java

public void debug(org.apache.commons.logging.Log log, String format, Object... option) {
    if (log.isDebugEnabled() && warnAgain()) {
        log.debug(String.format(format, option));
    }// w w  w .  j  a va 2s  .c  o m
}

From source file:edu.vt.middleware.crypt.CryptProvider.java

/**
 * <p>This finds a <code>Cipher</code> using the known providers and the
 * supplied parameters.</p>//from  www  .j  av a  2 s .  c om
 *
 * @param  algorithm  <code>String</code> name
 * @param  mode  <code>String</code> name
 * @param  padding  <code>String</code> name
 *
 * @return  <code>Cipher</code>
 *
 * @throws  CryptException  if the algorithm is not available from any
 * provider or if the provider is not available in the environment
 */
public static Cipher getCipher(final String algorithm, final String mode, final String padding)
        throws CryptException {
    final Log logger = LogFactory.getLog(CryptProvider.class);
    Cipher cipher = null;
    String transformation = null;
    if (mode != null && padding != null) {
        transformation = algorithm + "/" + mode + "/" + padding;
    } else if (mode != null) {
        transformation = algorithm + "/" + mode;
    } else {
        transformation = algorithm;
    }
    for (int i = 0; i < providers.length; i++) {
        try {
            cipher = Cipher.getInstance(transformation, providers[i]);
        } catch (NoSuchAlgorithmException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find algorithm " + algorithm + " in " + providers[i]);
            }
        } catch (NoSuchProviderException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find provider " + providers[i]);
            }
        } catch (NoSuchPaddingException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find padding " + padding + " in " + providers[i]);
            }
        } finally {
            if (cipher != null) {
                break;
            }
        }
    }
    if (cipher == null) {
        try {
            cipher = Cipher.getInstance(transformation);
        } catch (NoSuchAlgorithmException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find algorithm " + algorithm);
            }
            throw new CryptException(e.getMessage());
        } catch (NoSuchPaddingException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find padding " + padding);
            }
            throw new CryptException(e.getMessage());
        }
    }
    return cipher;
}

From source file:com.lucidtechnics.blackboard.util.error.ErrorManager.java

public void throwException(Throwable _t, Log _logger) {
    logException(_t, _logger);//from ww  w . ja v a 2  s  .  com

    if (_logger.isDebugEnabled() == true) {
        _logger.debug("ErrorManager Found this exception: " + _t.getClass());
    }

    if ((_t instanceof BlackboardException) == true) {
        throw (BlackboardException) _t;
    } else {
        throw new BlackboardException(_t);
    }
}

From source file:com.siblinks.ws.common.BaseException.java

public void log(final Log log) {
    if (errorLevel.equals(ErrorLevel.INFO) && log.isDebugEnabled()) {
        log.debug("Info Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.debug(StackTracer.getStackTrace(throwable));
    } else if (errorLevel.equals(ErrorLevel.WARNING) && log.isWarnEnabled()) {
        log.warn("Warn Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.warn(StackTracer.getStackTrace(throwable));
    } else if (errorLevel.equals(ErrorLevel.ERROR) && log.isErrorEnabled()) {
        log.error("Error Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.error(StackTracer.getStackTrace(throwable));
    } else if (errorLevel.equals(ErrorLevel.FATAL) && log.isFatalEnabled()) {
        log.fatal("Fatal Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.fatal(StackTracer.getStackTrace(throwable));
    }/*from  w  ww.j  a  v  a2s . c o m*/
    logged = true;
}

From source file:mockit.integration.logging.MoreLoggingIntegrationsTest.java

@Test
public void commonsLoggingShouldLogNothing() {
    Log log1 = LogFactory.getLog("test");

    assertFalse(log1.isTraceEnabled());//from  w  ww . j av  a 2s . com
    log1.error("testing that log does nothing");
    assertFalse(log1.isDebugEnabled());
}

From source file:edu.vt.middleware.crypt.CryptProvider.java

/**
 * <p>This finds a <code>Signature</code> using the known providers and the
 * supplied parameters.</p>//w ww.  j  a  v a 2s .  c o m
 *
 * @param  digestAlgorithm  <code>String</code> name
 * @param  algorithm  <code>String</code> name
 * @param  padding  <code>String</code> name
 *
 * @return  <code>Signature</code>
 *
 * @throws  CryptException  if the algorithm is not available from any
 * provider or if the provider is not available in the environment
 */
public static Signature getSignature(final String digestAlgorithm, final String algorithm, final String padding)
        throws CryptException {
    final Log logger = LogFactory.getLog(CryptProvider.class);
    Signature sig = null;
    String transformation = null;
    if (digestAlgorithm != null && padding != null) {
        transformation = digestAlgorithm + "/" + algorithm + "/" + padding;
    } else if (digestAlgorithm != null) {
        transformation = digestAlgorithm + "/" + algorithm;
    } else {
        transformation = algorithm;
    }
    for (int i = 0; i < providers.length; i++) {
        try {
            sig = Signature.getInstance(transformation, providers[i]);
        } catch (NoSuchAlgorithmException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find algorithm " + algorithm + " in " + providers[i]);
            }
        } catch (NoSuchProviderException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find provider " + providers[i]);
            }
        } finally {
            if (sig != null) {
                break;
            }
        }
    }
    if (sig == null) {
        try {
            sig = Signature.getInstance(transformation);
        } catch (NoSuchAlgorithmException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not find algorithm " + algorithm);
            }
            throw new CryptException(e.getMessage());
        }
    }
    return sig;
}

From source file:dk.statsbiblioteket.util.Logs.java

/**
 * Log the message and the elements to the log at the specified level.
 * Elements are converted to Strings and appended to the message. Arrays,
 * Lists and similar in the elements are expanded to a certain degree of
 * detail.//from w  w w .  j  a va 2s.com
 *
 * Sample input/output:
 * <code>log(myLog, Level.TRACE, false, "Started test", null,
 * 5, new String[]{"flim", "flam"});</code>
 * expands to
 * <code>log.trace("Started test (5, (flim, flam))");</code>
 *
 * @param log      the log to log to.
 * @param level    the level to log to (e.g. TRACE, DEBUG, INFO...).
 * @param verbose  if true, the elements are expanded more than for false.
 * @param error    the cause of this logging. If null, no cause is logged.
 * @param message  the message for the log.
 * @param elements the elements to log.
 */
public static void log(Log log, Level level, String message, Throwable error, boolean verbose,
        Object... elements) {
    int maxLength = verbose ? VERBOSE_MAXLENGTH : DEFAULT_MAXLENGTH;
    int maxDepth = verbose ? VERBOSE_MAXDEPTH : DEFAULT_MAXDEPTH;
    String expanded = message;
    if (elements != null && elements.length > 0) {
        expanded += expand(elements, maxLength, maxDepth);
    }
    switch (level) {
    case TRACE:
        if (!log.isTraceEnabled()) {
            return;
        }
        if (error == null) {
            log.trace(expanded);
        } else {
            log.trace(expanded, error);
        }
        break;
    case DEBUG:
        if (!log.isDebugEnabled()) {
            return;
        }
        if (error == null) {
            log.debug(expanded);
        } else {
            log.debug(expanded, error);
        }
        break;
    case INFO:
        if (!log.isInfoEnabled()) {
            return;
        }
        if (error == null) {
            log.info(expanded);
        } else {
            log.info(expanded, error);
        }
        break;
    case WARN:
        if (!log.isWarnEnabled()) {
            return;
        }
        if (error == null) {
            log.warn(expanded);
        } else {
            log.warn(expanded, error);
        }
        break;
    case ERROR:
        if (!log.isErrorEnabled()) {
            return;
        }
        if (error == null) {
            log.error(expanded);
        } else {
            log.error(expanded, error);
        }
        break;
    case FATAL:
        if (!log.isFatalEnabled()) {
            return;
        }
        if (error == null) {
            log.fatal(expanded);
        } else {
            log.fatal(expanded, error);
        }
        break;
    default:
        throw new IllegalArgumentException("The level '" + level + "' is unknown");
    }
}