|
24 | 24 | import org.springframework.util.Assert;
|
25 | 25 |
|
26 | 26 | /**
|
27 |
| - * A {@link CacheErrorHandler} implementation that logs error message. Can be |
28 |
| - * used when underlying cache errors should be ignored. |
| 27 | + * A {@link CacheErrorHandler} implementation that logs error messages. |
| 28 | + * |
| 29 | + * <p>Can be used when underlying cache errors should be ignored. |
29 | 30 | *
|
30 | 31 | * @author Adam Ostrožlík
|
31 | 32 | * @author Stephane Nicoll
|
| 33 | + * @author Vedran Pavic |
| 34 | + * @author Sam Brannen |
32 | 35 | * @since 5.3.16
|
33 | 36 | */
|
34 | 37 | public class LoggingCacheErrorHandler implements CacheErrorHandler {
|
35 | 38 |
|
36 | 39 | private final Log logger;
|
37 | 40 |
|
38 |
| - private final boolean logStacktrace; |
| 41 | + private final boolean logStackTraces; |
39 | 42 |
|
40 | 43 |
|
41 | 44 | /**
|
42 |
| - * Create an instance with the {@link Log logger} to use. |
43 |
| - * @param logger the logger to use |
44 |
| - * @param logStacktrace whether to log stack trace |
| 45 | + * Create a {@code LoggingCacheErrorHandler} that uses the default logging |
| 46 | + * category and does not log stack traces. |
| 47 | + * <p>The default logging category is |
| 48 | + * "{@code org.springframework.cache.interceptor.LoggingCacheErrorHandler}". |
45 | 49 | */
|
46 |
| - public LoggingCacheErrorHandler(Log logger, boolean logStacktrace) { |
47 |
| - Assert.notNull(logger, "Logger must not be null"); |
48 |
| - this.logger = logger; |
49 |
| - this.logStacktrace = logStacktrace; |
| 50 | + public LoggingCacheErrorHandler() { |
| 51 | + this(false); |
50 | 52 | }
|
51 | 53 |
|
52 | 54 | /**
|
53 |
| - * Create an instance that does not log stack traces. |
| 55 | + * Create a {@code LoggingCacheErrorHandler} that uses the default logging |
| 56 | + * category and the supplied {@code logStackTraces} flag. |
| 57 | + * <p>The default logging category is |
| 58 | + * "{@code org.springframework.cache.interceptor.LoggingCacheErrorHandler}". |
| 59 | + * @param logStackTraces whether to log stack traces |
| 60 | + * @since 5.3.22 |
54 | 61 | */
|
55 |
| - public LoggingCacheErrorHandler() { |
56 |
| - this(LogFactory.getLog(LoggingCacheErrorHandler.class), false); |
| 62 | + public LoggingCacheErrorHandler(boolean logStackTraces) { |
| 63 | + this(LogFactory.getLog(LoggingCacheErrorHandler.class), logStackTraces); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Create a {@code LoggingCacheErrorHandler} that uses the supplied |
| 68 | + * {@link Log logger} and {@code logStackTraces} flag. |
| 69 | + * @param logger the logger to use |
| 70 | + * @param logStackTraces whether to log stack traces |
| 71 | + */ |
| 72 | + public LoggingCacheErrorHandler(Log logger, boolean logStackTraces) { |
| 73 | + Assert.notNull(logger, "'logger' must not be null"); |
| 74 | + this.logger = logger; |
| 75 | + this.logStackTraces = logStackTraces; |
57 | 76 | }
|
58 | 77 |
|
59 | 78 |
|
@@ -90,7 +109,7 @@ public void handleCacheClearError(RuntimeException exception, Cache cache) {
|
90 | 109 | * @param ex the exception
|
91 | 110 | */
|
92 | 111 | protected void logCacheError(Log logger, String message, RuntimeException ex) {
|
93 |
| - if (this.logStacktrace) { |
| 112 | + if (this.logStackTraces) { |
94 | 113 | logger.warn(message, ex);
|
95 | 114 | }
|
96 | 115 | else {
|
|
0 commit comments