From aceea82f019007cd93a8482cf402eb4aa0259f88 Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Wed, 22 Jun 2022 17:44:57 +0200 Subject: [PATCH] Avoid use of Commons Logging in LoggingCacheErrorHandler public API At present, creating LoggingCacheErrorHandler with custom logger requires use of Commons Logging API, as the appropriate constructor expects org.apache.commons.logging.Log instance. As Commons Logging is rarely the logging framework of choice in applications these days, interaction with its API might not be desirable. This commit adds LoggingCacheErrorHandler constructor that accepts logger name and thus avoids leaking out any details about the underlying logging framework, while also deprecating the existing constructor that accepts org.apache.commons.logging.Log. --- .../interceptor/LoggingCacheErrorHandler.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/LoggingCacheErrorHandler.java b/spring-context/src/main/java/org/springframework/cache/interceptor/LoggingCacheErrorHandler.java index bfb821e350d8..9c31960b693c 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/LoggingCacheErrorHandler.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/LoggingCacheErrorHandler.java @@ -62,7 +62,20 @@ public LoggingCacheErrorHandler() { * @since 5.3.22 */ public LoggingCacheErrorHandler(boolean logStackTraces) { - this(LogFactory.getLog(LoggingCacheErrorHandler.class), logStackTraces); + this(LoggingCacheErrorHandler.class.getName(), 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.22 + */ + public LoggingCacheErrorHandler(String loggerName, boolean logStackTraces) { + Assert.notNull(loggerName, "'loggerName' must not be null"); + this.logger = LogFactory.getLog(loggerName); + this.logStackTraces = logStackTraces; } /** @@ -70,7 +83,9 @@ public LoggingCacheErrorHandler(boolean logStackTraces) { * {@link Log logger} and {@code logStackTraces} flag. * @param logger the logger to use * @param logStackTraces whether to log stack traces + * @deprecated since 5.3.22 in favor of {@link #LoggingCacheErrorHandler(String, boolean)} */ + @Deprecated public LoggingCacheErrorHandler(Log logger, boolean logStackTraces) { Assert.notNull(logger, "'logger' must not be null"); this.logger = logger;