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:org.springframework.kafka.support.SeekUtils.java

/**
 * Seek records to earliest position, optionally skipping the first.
 * @param records the records./*from   ww w. ja v  a2  s  .  c o  m*/
 * @param consumer the consumer.
 * @param exception the exception
 * @param recoverable true if skipping the first record is allowed.
 * @param skipper function to determine whether or not to skip seeking the first.
 * @param logger a {@link Log} for seek errors.
 * @return true if the failed record was skipped.
 */
public static boolean doSeeks(List<ConsumerRecord<?, ?>> records, Consumer<?, ?> consumer, Exception exception,
        boolean recoverable, BiPredicate<ConsumerRecord<?, ?>, Exception> skipper, Log logger) {
    Map<TopicPartition, Long> partitions = new LinkedHashMap<>();
    AtomicBoolean first = new AtomicBoolean(true);
    AtomicBoolean skipped = new AtomicBoolean();
    records.forEach(record -> {
        if (recoverable && first.get()) {
            skipped.set(skipper.test(record, exception));
            if (skipped.get() && logger.isDebugEnabled()) {
                logger.debug("Skipping seek of: " + record);
            }
        }
        if (!recoverable || !first.get() || !skipped.get()) {
            partitions.computeIfAbsent(new TopicPartition(record.topic(), record.partition()),
                    offset -> record.offset());
        }
        first.set(false);
    });
    boolean tracing = logger.isTraceEnabled();
    partitions.forEach((topicPartition, offset) -> {
        try {
            if (tracing) {
                logger.trace("Seeking: " + topicPartition + " to: " + offset);
            }
            consumer.seek(topicPartition, offset);
        } catch (Exception e) {
            logger.error("Failed to seek " + topicPartition + " to " + offset, e);
        }
    });
    return skipped.get();
}

From source file:org.springframework.orm.toplink.support.CommonsLoggingSessionLog.java

public void log(SessionLogEntry entry) {
    Log logger = LogFactory.getLog(getCategory(entry));
    switch (entry.getLevel()) {
    case SEVERE://from  w  ww . j a v  a2  s .c om
        if (logger.isErrorEnabled()) {
            if (entry.hasException()) {
                logger.error(getMessageString(entry), getException(entry));
            } else {
                logger.error(getMessageString(entry));
            }
        }
        break;
    case WARNING:
        if (logger.isWarnEnabled()) {
            if (entry.hasException()) {
                logger.warn(getMessageString(entry), getException(entry));
            } else {
                logger.warn(getMessageString(entry));
            }
        }
        break;
    case INFO:
        if (logger.isInfoEnabled()) {
            if (entry.hasException()) {
                logger.info(getMessageString(entry), getException(entry));
            } else {
                logger.info(getMessageString(entry));
            }
        }
        break;
    case CONFIG:
    case FINE:
    case FINER:
        if (logger.isDebugEnabled()) {
            if (entry.hasException()) {
                logger.debug(getMessageString(entry), getException(entry));
            } else {
                logger.debug(getMessageString(entry));
            }
        }
        break;
    case FINEST:
        if (logger.isTraceEnabled()) {
            if (entry.hasException()) {
                logger.trace(getMessageString(entry), getException(entry));
            } else {
                logger.trace(getMessageString(entry));
            }
        }
        break;
    }
}

From source file:org.springframework.security.web.session.HttpSessionEventPublisher.java

/**
 * Handles the HttpSessionEvent by publishing a {@link HttpSessionCreatedEvent} to the
 * application appContext./* ww w.  ja  v a  2 s  . c  o m*/
 *
 * @param event HttpSessionEvent passed in by the container
 */
public void sessionCreated(HttpSessionEvent event) {
    HttpSessionCreatedEvent e = new HttpSessionCreatedEvent(event.getSession());
    Log log = LogFactory.getLog(LOGGER_NAME);

    if (log.isDebugEnabled()) {
        log.debug("Publishing event: " + e);
    }

    getContext(event.getSession().getServletContext()).publishEvent(e);
}

From source file:org.springframework.security.web.session.HttpSessionEventPublisher.java

/**
 * Handles the HttpSessionEvent by publishing a {@link HttpSessionDestroyedEvent} to
 * the application appContext.//from  ww w .j  av a2s . c  o m
 *
 * @param event The HttpSessionEvent pass in by the container
 */
public void sessionDestroyed(HttpSessionEvent event) {
    HttpSessionDestroyedEvent e = new HttpSessionDestroyedEvent(event.getSession());
    Log log = LogFactory.getLog(LOGGER_NAME);

    if (log.isDebugEnabled()) {
        log.debug("Publishing event: " + e);
    }

    getContext(event.getSession().getServletContext()).publishEvent(e);
}

From source file:org.springframework.web.context.ContextLoader.java

/**
 * Initialize Spring's web application context for the given servlet 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 servletContext current servlet context
 * @return the new WebApplicationContext
 * @see #ContextLoader(WebApplicationContext)
 * @see #CONTEXT_CLASS_PARAM// w  w w. jav  a  2 s.  co  m
 * @see #CONFIG_LOCATION_PARAM
 */
public WebApplicationContext initWebApplicationContext(ServletContext servletContext) {
    if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
        throw new IllegalStateException(
                "Cannot initialize context because there is already a root application context present - "
                        + "check whether you have multiple ContextLoader* definitions in your web.xml!");
    }

    Log logger = LogFactory.getLog(ContextLoader.class);
    servletContext.log("Initializing Spring root WebApplicationContext");
    if (logger.isInfoEnabled()) {
        logger.info("Root WebApplicationContext: initialization started");
    }
    long startTime = System.currentTimeMillis();

    try {
        // Store context in local instance variable, to guarantee that
        // it is available on ServletContext shutdown.
        if (this.context == null) {
            this.context = createWebApplicationContext(servletContext);
        }
        if (this.context instanceof ConfigurableWebApplicationContext) {
            ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context;
            if (!cwac.isActive()) {
                // The context has not yet been refreshed -> provide services such as
                // setting the parent context, setting the application context id, etc
                if (cwac.getParent() == null) {
                    // The context instance was injected without an explicit parent ->
                    // determine parent for root web application context, if any.
                    ApplicationContext parent = loadParentContext(servletContext);
                    cwac.setParent(parent);
                }
                configureAndRefreshWebApplicationContext(cwac, servletContext);
            }
        }
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);

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

        if (logger.isDebugEnabled()) {
            logger.debug("Published root WebApplicationContext as ServletContext attribute with name ["
                    + WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");
        }
        if (logger.isInfoEnabled()) {
            long elapsedTime = System.currentTimeMillis() - startTime;
            logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
        }

        return this.context;
    } catch (RuntimeException ex) {
        logger.error("Context initialization failed", ex);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
        throw ex;
    } catch (Error err) {
        logger.error("Context initialization failed", err);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err);
        throw err;
    }
}

From source file:org.swordess.ldap.util.LogUtils.java

public static void debug(Log log, Object message) {
    if (log.isDebugEnabled()) {
        log.debug(message);
    }
}

From source file:org.swordess.ldap.util.LogUtils.java

public static void debug(Log log, Object message, Throwable t) {
    if (log.isDebugEnabled()) {
        log.debug(message, t);/*w  w  w  .j av a2 s. c o m*/
    }
}

From source file:org.talframework.tal.aspects.loggers.http.DefaultRequestLogger.java

/**
 * Logs out the request parameters and optionally the
 * request attributes for the first {@link HttpServletRequest}
 * argument to method.//from   w  ww . j  a  v a  2s .co m
 */
public void traceBefore(JoinPoint jp) {
    if (!logger.isDebugEnabled())
        return;

    Log logger = LoggerHelper.getLogger(jp.getStaticPart().getSignature().getDeclaringType());
    if (logger.isDebugEnabled()) {
        HttpServletRequest req = findRequest(jp);
        if (req == null)
            return;

        if (logger.isDebugEnabled())
            logRequestParameters(req, logger);
        if (logger.isTraceEnabled())
            logRequestAttributes(req, logger);
    }
}

From source file:org.talframework.tal.aspects.loggers.http.DefaultRequestLogger.java

/**
 * Optionally logs out the ending request attributes and
 * session for the first {@link HttpServletRequest} argument
 * to the method. /*from  w  w  w  . ja  v a2 s. c  om*/
 */
public void traceAfter(JoinPoint jp, Object retVal) {
    if (!logger.isDebugEnabled())
        return;

    Log logger = LoggerHelper.getLogger(jp.getStaticPart().getSignature().getDeclaringType());
    if (logger.isDebugEnabled()) {
        HttpServletRequest req = findRequest(jp);
        if (req == null)
            return;

        if (logger.isTraceEnabled())
            logRequestAttributes(req, logger);
        if (logger.isDebugEnabled())
            logSessionAttributes(req, logger);
    }
}

From source file:org.talframework.tal.aspects.loggers.trace.DefaultExceptionLogger.java

/**
 * Logs out that the method has failed listing out the full
 * input parameters and the exception. Logging is done as
 * error level//from   ww w.  j  ava  2 s  .  co m
 */
public void traceException(JoinPoint jp, Throwable t) {
    Log traceLogger = LoggerHelper.getLogger(jp.getStaticPart().getSignature().getDeclaringType());
    StringBuilder builder = new StringBuilder();

    builder.append("!!! Error From: ").append(jp.getStaticPart().getSignature().getName());
    builder.append("\n\texception=").append(t);
    LoggerHelper.appendArguments(jp.getArgs(), builder);

    traceLogger.error(builder.toString());
    if (traceLogger.isDebugEnabled())
        t.printStackTrace();
}