Skip to content

Commit 7f1990e

Browse files
committed
Merge branch '5.3.x'
2 parents d4f7484 + 4c38777 commit 7f1990e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ public LoggingCacheErrorHandler(Log logger, boolean logStackTraces) {
7777
this.logStackTraces = logStackTraces;
7878
}
7979

80+
/**
81+
* Create a {@code LoggingCacheErrorHandler} that uses the supplied
82+
* {@code loggerName} and {@code logStackTraces} flag.
83+
* @param loggerName the name of the logger to use. The name will be passed
84+
* to the underlying logger implementation through Commons Logging, getting
85+
* interpreted as log category according to the logger's configuration.
86+
* @param logStackTraces whether to log stack traces
87+
* @since 5.3.24
88+
* @see org.apache.commons.logging.LogFactory#getLog(String)
89+
* @see java.util.logging.Logger#getLogger(String)
90+
*/
91+
public LoggingCacheErrorHandler(String loggerName, boolean logStackTraces) {
92+
Assert.notNull(loggerName, "'loggerName' must not be null");
93+
this.logger = LogFactory.getLog(loggerName);
94+
this.logStackTraces = logStackTraces;
95+
}
96+
8097

8198
@Override
8299
public void handleCacheGetError(RuntimeException exception, Cache cache, Object key) {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.cache.Cache;
2424
import org.springframework.cache.support.NoOpCache;
2525

26+
import static org.assertj.core.api.Assertions.assertThatCode;
2627
import static org.mockito.BDDMockito.given;
2728
import static org.mockito.Mockito.mock;
2829
import static org.mockito.Mockito.verify;
@@ -84,4 +85,10 @@ void handleGetCacheErrorWithStackTraceLoggingEnabled() {
8485
verify(this.logger).warn("Cache 'NOOP' failed to get entry with key 'enigma'", exception);
8586
}
8687

88+
@Test
89+
void constructorWithLoggerName() {
90+
assertThatCode(() -> new LoggingCacheErrorHandler("org.apache.commons.logging.Log", true))
91+
.doesNotThrowAnyException();
92+
}
93+
8794
}

0 commit comments

Comments
 (0)