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.amqp.rabbit.connection.SSLConnectionTests.java

@Test
public void testNullTS() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    Log logger = spy(TestUtils.getPropertyValue(fb, "logger", Log.class));
    given(logger.isDebugEnabled()).willReturn(true);
    new DirectFieldAccessor(fb).setPropertyValue("logger", logger);
    fb.setUseSSL(true);/*www .  jav  a 2  s.  c  o  m*/
    fb.setKeyStoreType("JKS");
    fb.setKeyStoreResource(new ClassPathResource("test.ks"));
    fb.setKeyStorePassphrase("secret");
    fb.afterPropertiesSet();
    fb.getObject();
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(logger).debug(captor.capture());
    final String log = captor.getValue();
    assertThat(log, allOf(containsString("KM: ["), containsString("TM: null"), containsString("random: null")));
}

From source file:org.springframework.amqp.rabbit.connection.SSLConnectionTests.java

@Test
public void testNullKS() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    Log logger = spy(TestUtils.getPropertyValue(fb, "logger", Log.class));
    given(logger.isDebugEnabled()).willReturn(true);
    new DirectFieldAccessor(fb).setPropertyValue("logger", logger);
    fb.setUseSSL(true);/*from w w w . java 2s .  c  o  m*/
    fb.setKeyStoreType("JKS");
    fb.setTrustStoreResource(new ClassPathResource("test.truststore.ks"));
    fb.setKeyStorePassphrase("secret");
    fb.afterPropertiesSet();
    fb.getObject();
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(logger).debug(captor.capture());
    final String log = captor.getValue();
    assertThat(log, allOf(containsString("KM: null"), containsString("TM: ["), containsString("random: null")));
}

From source file:org.springframework.amqp.rabbit.listener.ContainerUtils.java

/**
 * Determine whether a message should be requeued; returns true if the throwable is a
 * {@link MessageRejectedWhileStoppingException} or defaultRequeueRejected is true and
 * there is not an {@link AmqpRejectAndDontRequeueException} in the cause chain.
 * @param defaultRequeueRejected the default requeue rejected.
 * @param throwable the throwable./*from   w w w  .  j  a  v a 2 s . co m*/
 * @param logger the logger to use for debug.
 * @return true to requeue.
 */
public static boolean shouldRequeue(boolean defaultRequeueRejected, Throwable throwable, Log logger) {
    boolean shouldRequeue = defaultRequeueRejected
            || throwable instanceof MessageRejectedWhileStoppingException;
    Throwable t = throwable;
    while (shouldRequeue && t != null) {
        if (t instanceof AmqpRejectAndDontRequeueException) {
            shouldRequeue = false;
        }
        t = t.getCause();
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Rejecting messages (requeue=" + shouldRequeue + ")");
    }
    return shouldRequeue;
}

From source file:org.springframework.boot.autoconfigure.condition.ConditionLogUtils.java

public static String getPrefix(Log logger, AnnotatedTypeMetadata metadata) {
    String prefix = "";
    if (logger.isDebugEnabled()) {
        prefix = metadata instanceof ClassMetadata
                ? "Processing " + ((ClassMetadata) metadata).getClassName() + ". "
                : (metadata instanceof MethodMetadata
                        ? "Processing " + getMethodName((MethodMetadata) metadata) + ". "
                        : "");
    }//from  w w  w . jav  a2  s.c  o m
    return prefix;
}

From source file:org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.java

/**
 * Prepare the {@link WebApplicationContext} with the given fully loaded
 * {@link ServletContext}. This method is usually called from
 * {@link ServletContextInitializer#onStartup(ServletContext)} and is similar to the
 * functionality usually provided by a {@link ContextLoaderListener}.
 * @param servletContext the operational servlet context
 *//*from   ww w . ja v a2 s  .  c o m*/
protected void prepareEmbeddedWebApplicationContext(ServletContext servletContext) {
    Object rootContext = servletContext
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    if (rootContext != null) {
        if (rootContext == this) {
            throw new IllegalStateException(
                    "Cannot initialize context because there is already a root application context present - "
                            + "check whether you have multiple ServletContextInitializers!");
        }
        return;
    }
    Log logger = LogFactory.getLog(ContextLoader.class);
    servletContext.log("Initializing Spring embedded WebApplicationContext");
    try {
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this);
        if (logger.isDebugEnabled()) {
            logger.debug("Published root WebApplicationContext as ServletContext attribute with name ["
                    + WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");
        }
        setServletContext(servletContext);
        if (logger.isInfoEnabled()) {
            long elapsedTime = System.currentTimeMillis() - getStartupDate();
            logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
        }
    } catch (RuntimeException ex) {
        logger.error("Context initialization failed", ex);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
        throw ex;
    } catch (Error ex) {
        logger.error("Context initialization failed", ex);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
        throw ex;
    }
}

From source file:org.springframework.boot.devtools.restart.classloader.RestartClassLoader.java

/**
 * Create a new {@link RestartClassLoader} instance.
 * @param parent the parent classloader/*from  ww  w  .j ava  2s .  co  m*/
 * @param updatedFiles any files that have been updated since the JARs referenced in
 * URLs were created.
 * @param urls the urls managed by the classloader
 * @param logger the logger used for messages
 */
public RestartClassLoader(ClassLoader parent, URL[] urls, ClassLoaderFileRepository updatedFiles, Log logger) {
    super(urls, parent);
    Assert.notNull(parent, "Parent must not be null");
    Assert.notNull(updatedFiles, "UpdatedFiles must not be null");
    Assert.notNull(logger, "Logger must not be null");
    this.updatedFiles = updatedFiles;
    this.logger = logger;
    if (logger.isDebugEnabled()) {
        logger.debug("Created RestartClassLoader " + toString());
    }
}

From source file:org.springframework.boot.legacy.context.web.NonEmbeddedWebApplicationContext.java

/**
 * Prepare the {@link WebApplicationContext} with the given fully loaded
 * {@link ServletContext}. This method is usually called from
 * {@link ServletContextInitializer#onStartup(ServletContext)} and is similar to the
 * functionality usually provided by a {@link ContextLoaderListener}.
 * @param servletContext the operational servlet context
 *///from w  ww. j  av a 2s.  com
protected void prepareWebApplicationContext(ServletContext servletContext) {
    Object rootContext = servletContext
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    if (rootContext != null) {
        if (rootContext == this) {
            throw new IllegalStateException(
                    "Cannot initialize context because there is already a root application context present - "
                            + "check whether you have multiple ServletContextInitializers!");
        } else {
            return;
        }
    }
    Log logger = LogFactory.getLog(ContextLoader.class);
    servletContext.log("Initializing Spring embedded WebApplicationContext");
    WebApplicationContextUtils.registerWebApplicationScopes(getBeanFactory(), getServletContext());
    WebApplicationContextUtils.registerEnvironmentBeans(getBeanFactory(), getServletContext());
    try {
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this);
        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() - getStartupDate();
            logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
        }
    } catch (RuntimeException ex) {
        logger.error("Context initialization failed", ex);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
        throw ex;
    } catch (Error ex) {
        logger.error("Context initialization failed", ex);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
        throw ex;
    }
}

From source file:org.springframework.boot.StartupInfoLogger.java

public void logStarting(Log log) {
    Assert.notNull(log, "Log must not be null");
    if (log.isInfoEnabled()) {
        log.info(getStartupMessage());/*from  w ww  . j av a  2 s.c  o  m*/
    }
    if (log.isDebugEnabled()) {
        log.debug(getRunningMessage());
    }
}

From source file:org.springframework.boot.util.LambdaSafeTests.java

@Test
@SuppressWarnings("unchecked")
public void callbackWithLoggerShouldUseLogger() {
    Log logger = mock(Log.class);
    given(logger.isDebugEnabled()).willReturn(true);
    GenericCallback<StringBuilder> callbackInstance = (s) -> fail("Should not get here");
    String argument = "foo";
    LambdaSafe.callback(GenericCallback.class, callbackInstance, argument).withLogger(logger)
            .invoke((c) -> c.handle(argument));
    verify(logger).debug(// w ww.  java 2  s . c  om
            contains("Non-matching CharSequence type for callback " + "LambdaSafeTests.GenericCallback"),
            any(Throwable.class));
}

From source file:org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor.java

private void logLambdaDebug(WebServerFactoryCustomizer<?> customizer, ClassCastException ex) {
    Log logger = LogFactory.getLog(getClass());
    if (logger.isDebugEnabled()) {
        logger.debug("Non-matching factory type for customizer: " + customizer, ex);
    }/*from w ww  .j  ava  2 s .  c o m*/
}