Skip to content

Commit

Permalink
Avoid use of Commons Logging in LoggingCacheErrorHandler public API
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vpavic committed Jun 22, 2022
1 parent 0783f07 commit aceea82
Showing 1 changed file with 16 additions and 1 deletion.
Expand Up @@ -62,15 +62,30 @@ 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;
}

/**
* Create a {@code LoggingCacheErrorHandler} that uses the supplied
* {@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;
Expand Down

0 comments on commit aceea82

Please sign in to comment.