Search in sources :

Example 76 with Log

use of org.apache.commons.logging.Log in project spring-framework by spring-projects.

the class PerformanceMonitorInterceptorTests method testExceptionPathStillLogsPerformanceMetricsCorrectly.

@Test
public void testExceptionPathStillLogsPerformanceMetricsCorrectly() throws Throwable {
    MethodInvocation mi = mock(MethodInvocation.class);
    given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
    given(mi.proceed()).willThrow(new IllegalArgumentException());
    Log log = mock(Log.class);
    PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
    assertThatIllegalArgumentException().isThrownBy(() -> interceptor.invokeUnderTrace(mi, log));
    verify(log).trace(anyString());
}
Also used : Log(org.apache.commons.logging.Log) MethodInvocation(org.aopalliance.intercept.MethodInvocation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Example 77 with Log

use of org.apache.commons.logging.Log in project spring-framework by spring-projects.

the class LoggingCacheErrorHandlerTests method handleGetCacheErrorLogsAppropriateMessage.

@Test
void handleGetCacheErrorLogsAppropriateMessage() {
    Log logger = mock(Log.class);
    LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
    handler.handleCacheGetError(new RuntimeException(), new NoOpCache("NOOP"), "key");
    verify(logger).warn("Cache 'NOOP' failed to get entry with key 'key'");
}
Also used : Log(org.apache.commons.logging.Log) NoOpCache(org.springframework.cache.support.NoOpCache) Test(org.junit.jupiter.api.Test)

Example 78 with Log

use of org.apache.commons.logging.Log in project spring-framework by spring-projects.

the class LoggingCacheErrorHandlerTests method handleClearErrorLogsAppropriateMessage.

@Test
void handleClearErrorLogsAppropriateMessage() {
    Log logger = mock(Log.class);
    LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
    handler.handleCacheClearError(new RuntimeException(), new NoOpCache("NOOP"));
    verify(logger).warn("Cache 'NOOP' failed to clear entries");
}
Also used : Log(org.apache.commons.logging.Log) NoOpCache(org.springframework.cache.support.NoOpCache) Test(org.junit.jupiter.api.Test)

Example 79 with Log

use of org.apache.commons.logging.Log in project spring-framework by spring-projects.

the class LoggingCacheErrorHandlerTests method handleCacheErrorWithStacktrace.

@Test
void handleCacheErrorWithStacktrace() {
    Log logger = mock(Log.class);
    LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, true);
    RuntimeException exception = new RuntimeException();
    handler.handleCacheGetError(exception, new NoOpCache("NOOP"), "key");
    verify(logger).warn("Cache 'NOOP' failed to get entry with key 'key'", exception);
}
Also used : Log(org.apache.commons.logging.Log) NoOpCache(org.springframework.cache.support.NoOpCache) Test(org.junit.jupiter.api.Test)

Example 80 with Log

use of org.apache.commons.logging.Log in project spring-framework by spring-projects.

the class DecoderHttpMessageReader method initLogger.

private static void initLogger(Decoder<?> decoder) {
    if (decoder instanceof AbstractDecoder && decoder.getClass().getName().startsWith("org.springframework.core.codec")) {
        Log logger = HttpLogging.forLog(((AbstractDecoder<?>) decoder).getLogger());
        ((AbstractDecoder<?>) decoder).setLogger(logger);
    }
}
Also used : Log(org.apache.commons.logging.Log) AbstractDecoder(org.springframework.core.codec.AbstractDecoder)

Aggregations

Log (org.apache.commons.logging.Log)188 Test (org.junit.Test)51 Test (org.junit.jupiter.api.Test)40 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)35 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 BeanFactory (org.springframework.beans.factory.BeanFactory)17 CountDownLatch (java.util.concurrent.CountDownLatch)15 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)15 ArrayList (java.util.ArrayList)12 File (java.io.File)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11 MethodInvocation (org.aopalliance.intercept.MethodInvocation)10 IOException (java.io.IOException)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)9 Message (org.springframework.messaging.Message)8 List (java.util.List)7 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)7 InputStream (java.io.InputStream)6 LogFactory (org.apache.commons.logging.LogFactory)6