Skip to content

Commit fac2e35

Browse files
committed
Refactor util.log.LogUtils into core.log.LogDelegateFactory
Issue: SPR-17012
1 parent 20c34cb commit fac2e35

File tree

9 files changed

+52
-36
lines changed

9 files changed

+52
-36
lines changed

spring-core/src/main/java/org/springframework/util/log/CompositeLog.java renamed to spring-core/src/main/java/org/springframework/core/log/CompositeLog.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.util.log;
16+
17+
package org.springframework.core.log;
1718

1819
import java.util.List;
1920
import java.util.function.Predicate;
@@ -22,16 +23,16 @@
2223
import org.apache.commons.logging.impl.NoOpLog;
2324

2425
/**
25-
* Implementation of {@link Log} that wraps a list of loggers and delegates to
26-
* the first one for which logging is enabled at the given level.
26+
* Implementation of {@link Log} that wraps a list of loggers and delegates
27+
* to the first one for which logging is enabled at the given level.
2728
*
2829
* @author Rossen Stoyanchev
2930
* @since 5.1
30-
* @see LogUtils#getCompositeLog
31+
* @see LogDelegateFactory#getCompositeLog
3132
*/
32-
class CompositeLog implements Log {
33+
final class CompositeLog implements Log {
3334

34-
private static final Log noOpLog = new NoOpLog();
35+
private static final Log NO_OP_LOG = new NoOpLog();
3536

3637

3738
private final Log fatalLogger;
@@ -62,38 +63,38 @@ public CompositeLog(List<Log> loggers) {
6263
}
6364

6465
private static Log initLogger(List<Log> loggers, Predicate<Log> predicate) {
65-
return loggers.stream().filter(predicate).findFirst().orElse(noOpLog);
66+
return loggers.stream().filter(predicate).findFirst().orElse(NO_OP_LOG);
6667
}
6768

6869

6970
@Override
7071
public boolean isFatalEnabled() {
71-
return this.fatalLogger != noOpLog;
72+
return this.fatalLogger != NO_OP_LOG;
7273
}
7374

7475
@Override
7576
public boolean isErrorEnabled() {
76-
return this.errorLogger != noOpLog;
77+
return this.errorLogger != NO_OP_LOG;
7778
}
7879

7980
@Override
8081
public boolean isWarnEnabled() {
81-
return this.warnLogger != noOpLog;
82+
return this.warnLogger != NO_OP_LOG;
8283
}
8384

8485
@Override
8586
public boolean isInfoEnabled() {
86-
return this.infoLogger != noOpLog;
87+
return this.infoLogger != NO_OP_LOG;
8788
}
8889

8990
@Override
9091
public boolean isDebugEnabled() {
91-
return this.debugLogger != noOpLog;
92+
return this.debugLogger != NO_OP_LOG;
9293
}
9394

9495
@Override
9596
public boolean isTraceEnabled() {
96-
return this.traceLogger != noOpLog;
97+
return this.traceLogger != NO_OP_LOG;
9798
}
9899

99100
@Override
@@ -155,4 +156,5 @@ public void trace(Object message) {
155156
public void trace(Object message, Throwable ex) {
156157
this.traceLogger.trace(message, ex);
157158
}
159+
158160
}

spring-core/src/main/java/org/springframework/util/log/LogUtils.java renamed to spring-core/src/main/java/org/springframework/core/log/LogDelegateFactory.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.util.log;
16+
17+
package org.springframework.core.log;
1718

1819
import java.util.ArrayList;
1920
import java.util.Collections;
@@ -23,13 +24,22 @@
2324
import org.apache.commons.logging.LogFactory;
2425

2526
/**
26-
* Utilities to assist with logging. Mainly for internal use within the framework
27-
* with Appache Commons Logging.
27+
* Factory for common {@link Log} delegates with Spring's logging conventions.
28+
*
29+
* <p>Mainly for internal use within the framework with Apache Commons Logging,
30+
* typically in the form of the {@code spring-jcl} bridge but also compatible
31+
* with other Commons Logging bridges.
2832
*
2933
* @author Rossen Stoyanchev
34+
* @author Juergen Hoeller
3035
* @since 5.1
36+
* @see org.apache.commons.logging.LogFactory
3137
*/
32-
public abstract class LogUtils {
38+
public final class LogDelegateFactory {
39+
40+
private LogDelegateFactory() {
41+
}
42+
3343

3444
/**
3545
* Create a composite logger that delegates to a primary or falls back on a
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
2-
* Useful helper classes for logging.
2+
* Useful delegates for Spring's logging conventions.
33
*/
44
@NonNullApi
55
@NonNullFields
6-
package org.springframework.util.log;
6+
package org.springframework.core.log;
77

88
import org.springframework.lang.NonNullApi;
99
import org.springframework.lang.NonNullFields;

spring-messaging/src/main/java/org/springframework/messaging/simp/SimpLogging.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.messaging.simp;
1718

1819
import org.apache.commons.logging.Log;
1920
import org.apache.commons.logging.LogFactory;
2021

21-
import org.springframework.util.log.LogUtils;
22+
import org.springframework.core.log.LogDelegateFactory;
2223

2324
/**
2425
* Holds the shared logger named "org.springframework.web.SimpLogging" to use
@@ -35,6 +36,7 @@
3536
*
3637
* @author Rossen Stoyanchev
3738
* @since 5.1
39+
* @see LogDelegateFactory
3840
*/
3941
public abstract class SimpLogging {
4042

@@ -62,7 +64,7 @@ public static Log forLogName(Class<?> primaryLoggerClass) {
6264
* @return the resulting composite logger
6365
*/
6466
public static Log forLog(Log primaryLogger) {
65-
return LogUtils.getCompositeLog(primaryLogger, fallbackLogger);
67+
return LogDelegateFactory.getCompositeLog(primaryLogger, fallbackLogger);
6668
}
6769

6870
}

spring-web/src/main/java/org/springframework/http/HttpLogging.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.http;
1718

1819
import org.apache.commons.logging.Log;
1920
import org.apache.commons.logging.LogFactory;
2021

21-
import org.springframework.util.log.LogUtils;
22+
import org.springframework.core.log.LogDelegateFactory;
2223

2324
/**
2425
* Holds the shared logger named "org.springframework.web.HttpLogging" for HTTP
@@ -36,6 +37,7 @@
3637
*
3738
* @author Rossen Stoyanchev
3839
* @since 5.1
40+
* @see LogDelegateFactory
3941
*/
4042
public abstract class HttpLogging {
4143

@@ -63,7 +65,7 @@ public static Log forLogName(Class<?> primaryLoggerClass) {
6365
* @return the resulting composite logger
6466
*/
6567
public static Log forLog(Log primaryLogger) {
66-
return LogUtils.getCompositeLog(primaryLogger, fallbackLogger);
68+
return LogDelegateFactory.getCompositeLog(primaryLogger, fallbackLogger);
6769
}
6870

6971
}

spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerReadPublisher.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import org.reactivestreams.Subscription;
2727
import reactor.core.publisher.Operators;
2828

29+
import org.springframework.core.log.LogDelegateFactory;
2930
import org.springframework.lang.Nullable;
3031
import org.springframework.util.Assert;
31-
import org.springframework.util.log.LogUtils;
3232

3333
/**
3434
* Abstract base class for {@code Publisher} implementations that bridge between
@@ -49,12 +49,12 @@ public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
4949

5050
/**
5151
* Special logger for debugging Reactive Streams signals.
52-
* @see LogUtils#getHiddenLog(Class)
52+
* @see LogDelegateFactory#getHiddenLog(Class)
5353
* @see AbstractListenerWriteProcessor#rsWriteLogger
5454
* @see AbstractListenerWriteFlushProcessor#rsWriteFlushLogger
5555
* @see WriteResultPublisher#rsWriteResultLogger
5656
*/
57-
protected static Log rsReadLogger = LogUtils.getHiddenLog(AbstractListenerReadPublisher.class);
57+
protected static Log rsReadLogger = LogDelegateFactory.getHiddenLog(AbstractListenerReadPublisher.class);
5858

5959

6060
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);

spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteFlushProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import org.reactivestreams.Subscriber;
2626
import org.reactivestreams.Subscription;
2727

28+
import org.springframework.core.log.LogDelegateFactory;
2829
import org.springframework.lang.Nullable;
2930
import org.springframework.util.Assert;
30-
import org.springframework.util.log.LogUtils;
3131

3232
/**
3333
* An alternative to {@link AbstractListenerWriteProcessor} but instead writing
@@ -44,12 +44,12 @@ public abstract class AbstractListenerWriteFlushProcessor<T> implements Processo
4444

4545
/**
4646
* Special logger for debugging Reactive Streams signals.
47-
* @see LogUtils#getHiddenLog(Class)
47+
* @see LogDelegateFactory#getHiddenLog(Class)
4848
* @see AbstractListenerReadPublisher#rsReadLogger
4949
* @see AbstractListenerWriteProcessor#rsWriteLogger
5050
* @see WriteResultPublisher#rsWriteResultLogger
5151
*/
52-
protected static final Log rsWriteFlushLogger = LogUtils.getHiddenLog(AbstractListenerWriteFlushProcessor.class);
52+
protected static final Log rsWriteFlushLogger = LogDelegateFactory.getHiddenLog(AbstractListenerWriteFlushProcessor.class);
5353

5454

5555
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);

spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import org.reactivestreams.Subscriber;
2525
import org.reactivestreams.Subscription;
2626

27+
import org.springframework.core.log.LogDelegateFactory;
2728
import org.springframework.lang.Nullable;
2829
import org.springframework.util.Assert;
29-
import org.springframework.util.log.LogUtils;
3030

3131
/**
3232
* Abstract base class for {@code Processor} implementations that bridge between
@@ -46,12 +46,12 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
4646

4747
/**
4848
* Special logger for debugging Reactive Streams signals.
49-
* @see LogUtils#getHiddenLog(Class)
49+
* @see LogDelegateFactory#getHiddenLog(Class)
5050
* @see AbstractListenerReadPublisher#rsReadLogger
5151
* @see AbstractListenerWriteFlushProcessor#rsWriteFlushLogger
5252
* @see WriteResultPublisher#rsWriteResultLogger
5353
*/
54-
protected static final Log rsWriteLogger = LogUtils.getHiddenLog(AbstractListenerWriteProcessor.class);
54+
protected static final Log rsWriteLogger = LogDelegateFactory.getHiddenLog(AbstractListenerWriteProcessor.class);
5555

5656

5757
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);

spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,9 +24,9 @@
2424
import org.reactivestreams.Subscription;
2525
import reactor.core.publisher.Operators;
2626

27+
import org.springframework.core.log.LogDelegateFactory;
2728
import org.springframework.lang.Nullable;
2829
import org.springframework.util.Assert;
29-
import org.springframework.util.log.LogUtils;
3030

3131
/**
3232
* Publisher returned from {@link ServerHttpResponse#writeWith(Publisher)}.
@@ -40,12 +40,12 @@ class WriteResultPublisher implements Publisher<Void> {
4040

4141
/**
4242
* Special logger for debugging Reactive Streams signals.
43-
* @see LogUtils#getHiddenLog(Class)
43+
* @see LogDelegateFactory#getHiddenLog(Class)
4444
* @see AbstractListenerReadPublisher#rsReadLogger
4545
* @see AbstractListenerWriteProcessor#rsWriteLogger
4646
* @see AbstractListenerWriteFlushProcessor#rsWriteFlushLogger
4747
*/
48-
private static final Log rsWriteResultLogger = LogUtils.getHiddenLog(WriteResultPublisher.class);
48+
private static final Log rsWriteResultLogger = LogDelegateFactory.getHiddenLog(WriteResultPublisher.class);
4949

5050

5151
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);

0 commit comments

Comments
 (0)