Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid Commons Logging API for using LoggingCacheErrorHandler with a custom logger #28678

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -77,6 +77,19 @@ public LoggingCacheErrorHandler(Log logger, boolean logStackTraces) {
this.logStackTraces = logStackTraces;
}

/**
* Create a {@code LoggingCacheErrorHandler} that uses the supplied
* {@code loggerName} and {@code logStackTraces} flag.
* @param loggerName the logger name to use
* @param logStackTraces whether to log stack traces
* @since 5.3.24
*/
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) {
Expand Down
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -84,4 +85,10 @@ void handleGetCacheErrorWithStackTraceLoggingEnabled() {
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();
}

}