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:com.amazon.carbonado.repo.jdbc.LoggingDataSource.java

/**
 * Wraps the given DataSource which logs to the given log. If debug logging
 * is disabled, the original DataSource is returned.
 *//* www . j ava  2 s .co  m*/
public static DataSource create(DataSource ds, Log log) {
    if (ds == null) {
        throw new IllegalArgumentException();
    }
    if (log == null) {
        log = LogFactory.getLog(LoggingDataSource.class);
    }
    if (!log.isDebugEnabled()) {
        return ds;
    }
    return new LoggingDataSource(log, ds);
}

From source file:com.intel.chimera.utils.IOUtils.java

/**
 * Closes the Closeable objects and <b>ignore</b> any {@link IOException} or
 * null pointers. Must only be used for cleanup in exception handlers.
 *
 * @param log the log to record problems to at debug level. Can be null.
 * @param closeables the objects to close.
 *///from www  .ja va2s . co m
public static void cleanup(Log log, java.io.Closeable... closeables) {
    for (java.io.Closeable c : closeables) {
        if (c != null) {
            try {
                c.close();
            } catch (Throwable e) {
                if (log != null && log.isDebugEnabled()) {
                    log.debug("Exception in closing " + c, e);
                }
            }
        }
    }
}

From source file:com.googlecode.jcimd.PacketSerializer.java

private static void doSerializePacket(Packet packet, PacketSequenceNumberGenerator sequenceNumberGenerator,
        boolean useChecksum, Log logger, OutputStream outputStream) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("Sending " + packet);
    }/*from  w ww  . j av  a  2 s  . c  om*/
    byte[] bytes = serializeToByteArray(packet, sequenceNumberGenerator, logger);
    outputStream.write(bytes);
    if (useChecksum) {
        int checkSum = calculateCheckSum(bytes);
        AsciiUtils.writeIntAsHexAsciiBytes(checkSum, outputStream, 2);
    }
    outputStream.write(ETX);
}

From source file:eu.stratosphere.nephele.util.IOUtils.java

/**
 * Close the Closeable objects and <b>ignore</b> any {@link IOException} or
 * null pointers. Must only be used for cleanup in exception handlers.
 * /*from w ww. j a va  2 s .co m*/
 * @param log
 *        the log to record problems to at debug level. Can be <code>null</code>.
 * @param closeables
 *        the objects to close
 */
public static void cleanup(final Log log, final java.io.Closeable... closeables) {
    for (java.io.Closeable c : closeables) {
        if (c != null) {
            try {
                c.close();
            } catch (IOException e) {
                if (log != null && log.isDebugEnabled()) {
                    log.debug("Exception in closing " + c, e);
                }
            }
        }
    }
}

From source file:com.jeeframework.util.validate.GenericTypeValidator.java

/**
 *  <p>/*from   w ww.ja v a  2 s .  c  om*/
 *
 *  Checks if the field is a valid date. The <code>Locale</code> is used
 *  with <code>java.text.DateFormat</code>. The setLenient method is set to
 *  <code>false</code> for all.</p>
 *
 *@param  value   The value validation is being performed on.
 *@param  locale  The Locale to use to parse the date (system default if
 *      null)
 *@return the converted Date value.
 */
public static Date formatDate(String value, Locale locale) {
    Date date = null;

    if (value == null) {
        return null;
    }

    try {
        DateFormat formatter = null;
        if (locale != null) {
            formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        } else {
            formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
        }

        formatter.setLenient(false);

        date = formatter.parse(value);
    } catch (ParseException e) {
        // Bad date so return null
        Log log = LogFactory.getLog(GenericTypeValidator.class);
        if (log.isDebugEnabled()) {
            log.debug("Date parse failed value=[" + value + "], " + "locale=[" + locale + "] " + e);
        }
    }

    return date;
}

From source file:com.jeeframework.util.validate.GenericTypeValidator.java

/**
 *  <p>/*from   w w w . ja  va  2s  . co m*/
 *  Checks if the field is a valid date. The pattern is used with <code>java.text.SimpleDateFormat</code>
 *  . If strict is true, then the length will be checked so '2/12/1999' will
 *  not pass validation with the format 'MM/dd/yyyy' because the month isn't
 *  two digits. The setLenient method is set to <code>false</code> for all.
 *  </p>
 *
 *@param  value        The value validation is being performed on.
 *@param  datePattern  The pattern passed to <code>SimpleDateFormat</code>.
 *@param  strict       Whether or not to have an exact match of the
 *      datePattern.
 *@return the converted Date value.
 */
public static Date formatDate(String value, String datePattern, boolean strict) {
    Date date = null;

    if (value == null || datePattern == null || datePattern.length() == 0) {
        return null;
    }

    try {
        SimpleDateFormat formatter = new SimpleDateFormat(datePattern);
        formatter.setLenient(false);

        date = formatter.parse(value);

        if (strict) {
            if (datePattern.length() != value.length()) {
                date = null;
            }
        }
    } catch (ParseException e) {
        // Bad date so return null
        Log log = LogFactory.getLog(GenericTypeValidator.class);
        if (log.isDebugEnabled()) {
            log.debug("Date parse failed value=[" + value + "], " + "pattern=[" + datePattern + "], "
                    + "strict=[" + strict + "] " + e);
        }
    }

    return date;
}

From source file:com.ery.ertc.estorm.util.IOUtils.java

/**
 * Close the Closeable objects and <b>ignore</b> any {@link IOException} or
 * null pointers. Must only be used for cleanup in exception handlers.
 * //  ww w  . jav  a 2  s .c  om
 * @param log
 *            the log to record problems to at debug level. Can be null.
 * @param closeables
 *            the objects to close
 */
public static void cleanup(Log log, java.io.Closeable... closeables) {
    for (java.io.Closeable c : closeables) {
        if (c != null) {
            try {
                c.close();
            } catch (IOException e) {
                if (log != null && log.isDebugEnabled()) {
                    log.debug("Exception in closing " + c, e);
                }
            }
        }
    }
}

From source file:com.buaa.cfs.utils.IOUtils.java

/**
 * Close the Closeable objects and <b>ignore</b> any {@link IOException} or null pointers. Must only be used for
 * cleanup in exception handlers./*from w  w w  .j a v  a 2 s . co  m*/
 *
 * @param log        the log to record problems to at debug level. Can be null.
 * @param closeables the objects to close
 */
public static void cleanup(Log log, Closeable... closeables) {
    for (Closeable c : closeables) {
        if (c != null) {
            try {
                c.close();
            } catch (IOException e) {
                if (log != null && log.isDebugEnabled()) {
                    log.debug("Exception in closing " + c, e);
                }
            }
        }
    }
}

From source file:de.itsvs.cwtrpc.core.CwtRpcUtils.java

public static void preloadContextClasses(ServletContext servletContext) throws ApplicationContextException {
    final Log log = LogFactory.getLog(CwtRpcUtils.class);
    final String preloadedClasses;

    preloadedClasses = servletContext.getInitParameter(PRELOADED_CLASSES_INIT_PARAM_NAME);
    if (preloadedClasses != null) {
        final String[] classNames = preloadedClasses.split("\\s");

        for (String className : classNames) {
            if (className.length() > 0) {
                if (log.isDebugEnabled()) {
                    log.debug("Preloading class: " + className);
                }//from  ww  w .  j  av a 2  s  .  co  m
                try {
                    CwtRpcUtils.class.getClassLoader().loadClass(className);
                } catch (ClassNotFoundException e) {
                    throw new ApplicationContextException("Could not load class '" + className + "'", e);
                }
            }
        }
    }
}

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

/**
 * <p>This will add an additional security provider.</p>
 *
 * @param  provider  <code>Provider</code>
 * @param  name  <code>String</code>
 *//*from   w w w  . j a  v a 2s  .c  om*/
public static void addProvider(final Provider provider, final String name) {
    java.security.Security.addProvider(provider);

    final String[] tmp = new String[providers.length + 1];
    for (int i = 0; i < providers.length; i++) {
        tmp[i] = providers[i];
    }
    tmp[providers.length] = name;
    providers = tmp;

    final Log logger = LogFactory.getLog(CryptProvider.class);
    if (logger.isDebugEnabled()) {
        logger.debug("Added new security provider " + name);
    }
}