Browse Source

Merge branch '5.3.x'

pull/29364/head
Juergen Hoeller 3 years ago
parent
commit
7f1990e64e
  1. 17
      spring-context/src/main/java/org/springframework/cache/interceptor/LoggingCacheErrorHandler.java
  2. 7
      spring-context/src/test/java/org/springframework/cache/interceptor/LoggingCacheErrorHandlerTests.java

17
spring-context/src/main/java/org/springframework/cache/interceptor/LoggingCacheErrorHandler.java vendored

@ -77,6 +77,23 @@ public class LoggingCacheErrorHandler implements CacheErrorHandler { @@ -77,6 +77,23 @@ public class LoggingCacheErrorHandler implements CacheErrorHandler {
this.logStackTraces = logStackTraces;
}
/**
* Create a {@code LoggingCacheErrorHandler} that uses the supplied
* {@code loggerName} and {@code logStackTraces} flag.
* @param loggerName the name of the logger to use. The name will be passed
* to the underlying logger implementation through Commons Logging, getting
* interpreted as log category according to the logger's configuration.
* @param logStackTraces whether to log stack traces
* @since 5.3.24
* @see org.apache.commons.logging.LogFactory#getLog(String)
* @see java.util.logging.Logger#getLogger(String)
*/
public LoggingCacheErrorHandler(String loggerName, boolean logStackTraces) {
Assert.notNull(loggerName, "'loggerName' must not be null");
this.logger = LogFactory.getLog(loggerName);
this.logStackTraces = logStackTraces;
}
@Override
public void handleCacheGetError(RuntimeException exception, Cache cache, Object key) {

7
spring-context/src/test/java/org/springframework/cache/interceptor/LoggingCacheErrorHandlerTests.java vendored

@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test; @@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.cache.Cache;
import org.springframework.cache.support.NoOpCache;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@ -84,4 +85,10 @@ class LoggingCacheErrorHandlerTests { @@ -84,4 +85,10 @@ class LoggingCacheErrorHandlerTests {
verify(this.logger).warn("Cache 'NOOP' failed to get entry with key 'enigma'", exception);
}
@Test
void constructorWithLoggerName() {
assertThatCode(() -> new LoggingCacheErrorHandler("org.apache.commons.logging.Log", true))
.doesNotThrowAnyException();
}
}

Loading…
Cancel
Save