Refactor util.log.LogUtils into core.log.LogDelegateFactory
Issue: SPR-17012
This commit is contained in:
parent
20c34cbb9b
commit
fac2e35f96
|
@ -13,7 +13,8 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.util.log;
|
|
||||||
|
package org.springframework.core.log;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
@ -22,16 +23,16 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.impl.NoOpLog;
|
import org.apache.commons.logging.impl.NoOpLog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link Log} that wraps a list of loggers and delegates to
|
* Implementation of {@link Log} that wraps a list of loggers and delegates
|
||||||
* the first one for which logging is enabled at the given level.
|
* to the first one for which logging is enabled at the given level.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
* @see LogUtils#getCompositeLog
|
* @see LogDelegateFactory#getCompositeLog
|
||||||
*/
|
*/
|
||||||
class CompositeLog implements Log {
|
final class CompositeLog implements Log {
|
||||||
|
|
||||||
private static final Log noOpLog = new NoOpLog();
|
private static final Log NO_OP_LOG = new NoOpLog();
|
||||||
|
|
||||||
|
|
||||||
private final Log fatalLogger;
|
private final Log fatalLogger;
|
||||||
|
@ -62,38 +63,38 @@ class CompositeLog implements Log {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Log initLogger(List<Log> loggers, Predicate<Log> predicate) {
|
private static Log initLogger(List<Log> loggers, Predicate<Log> predicate) {
|
||||||
return loggers.stream().filter(predicate).findFirst().orElse(noOpLog);
|
return loggers.stream().filter(predicate).findFirst().orElse(NO_OP_LOG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFatalEnabled() {
|
public boolean isFatalEnabled() {
|
||||||
return this.fatalLogger != noOpLog;
|
return this.fatalLogger != NO_OP_LOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isErrorEnabled() {
|
public boolean isErrorEnabled() {
|
||||||
return this.errorLogger != noOpLog;
|
return this.errorLogger != NO_OP_LOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWarnEnabled() {
|
public boolean isWarnEnabled() {
|
||||||
return this.warnLogger != noOpLog;
|
return this.warnLogger != NO_OP_LOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInfoEnabled() {
|
public boolean isInfoEnabled() {
|
||||||
return this.infoLogger != noOpLog;
|
return this.infoLogger != NO_OP_LOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDebugEnabled() {
|
public boolean isDebugEnabled() {
|
||||||
return this.debugLogger != noOpLog;
|
return this.debugLogger != NO_OP_LOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTraceEnabled() {
|
public boolean isTraceEnabled() {
|
||||||
return this.traceLogger != noOpLog;
|
return this.traceLogger != NO_OP_LOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -155,4 +156,5 @@ class CompositeLog implements Log {
|
||||||
public void trace(Object message, Throwable ex) {
|
public void trace(Object message, Throwable ex) {
|
||||||
this.traceLogger.trace(message, ex);
|
this.traceLogger.trace(message, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -13,7 +13,8 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.util.log;
|
|
||||||
|
package org.springframework.core.log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -23,13 +24,22 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities to assist with logging. Mainly for internal use within the framework
|
* Factory for common {@link Log} delegates with Spring's logging conventions.
|
||||||
* with Appache Commons Logging.
|
*
|
||||||
|
* <p>Mainly for internal use within the framework with Apache Commons Logging,
|
||||||
|
* typically in the form of the {@code spring-jcl} bridge but also compatible
|
||||||
|
* with other Commons Logging bridges.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
|
* @author Juergen Hoeller
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
|
* @see org.apache.commons.logging.LogFactory
|
||||||
*/
|
*/
|
||||||
public abstract class LogUtils {
|
public final class LogDelegateFactory {
|
||||||
|
|
||||||
|
private LogDelegateFactory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a composite logger that delegates to a primary or falls back on a
|
* Create a composite logger that delegates to a primary or falls back on a
|
|
@ -1,9 +1,9 @@
|
||||||
/**
|
/**
|
||||||
* Useful helper classes for logging.
|
* Useful delegates for Spring's logging conventions.
|
||||||
*/
|
*/
|
||||||
@NonNullApi
|
@NonNullApi
|
||||||
@NonNullFields
|
@NonNullFields
|
||||||
package org.springframework.util.log;
|
package org.springframework.core.log;
|
||||||
|
|
||||||
import org.springframework.lang.NonNullApi;
|
import org.springframework.lang.NonNullApi;
|
||||||
import org.springframework.lang.NonNullFields;
|
import org.springframework.lang.NonNullFields;
|
|
@ -13,12 +13,13 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.messaging.simp;
|
package org.springframework.messaging.simp;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.util.log.LogUtils;
|
import org.springframework.core.log.LogDelegateFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the shared logger named "org.springframework.web.SimpLogging" to use
|
* Holds the shared logger named "org.springframework.web.SimpLogging" to use
|
||||||
|
@ -35,6 +36,7 @@ import org.springframework.util.log.LogUtils;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
|
* @see LogDelegateFactory
|
||||||
*/
|
*/
|
||||||
public abstract class SimpLogging {
|
public abstract class SimpLogging {
|
||||||
|
|
||||||
|
@ -62,7 +64,7 @@ public abstract class SimpLogging {
|
||||||
* @return the resulting composite logger
|
* @return the resulting composite logger
|
||||||
*/
|
*/
|
||||||
public static Log forLog(Log primaryLogger) {
|
public static Log forLog(Log primaryLogger) {
|
||||||
return LogUtils.getCompositeLog(primaryLogger, fallbackLogger);
|
return LogDelegateFactory.getCompositeLog(primaryLogger, fallbackLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,13 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.http;
|
package org.springframework.http;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.util.log.LogUtils;
|
import org.springframework.core.log.LogDelegateFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the shared logger named "org.springframework.web.HttpLogging" for HTTP
|
* Holds the shared logger named "org.springframework.web.HttpLogging" for HTTP
|
||||||
|
@ -36,6 +37,7 @@ import org.springframework.util.log.LogUtils;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
|
* @see LogDelegateFactory
|
||||||
*/
|
*/
|
||||||
public abstract class HttpLogging {
|
public abstract class HttpLogging {
|
||||||
|
|
||||||
|
@ -63,7 +65,7 @@ public abstract class HttpLogging {
|
||||||
* @return the resulting composite logger
|
* @return the resulting composite logger
|
||||||
*/
|
*/
|
||||||
public static Log forLog(Log primaryLogger) {
|
public static Log forLog(Log primaryLogger) {
|
||||||
return LogUtils.getCompositeLog(primaryLogger, fallbackLogger);
|
return LogDelegateFactory.getCompositeLog(primaryLogger, fallbackLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,9 @@ import org.reactivestreams.Subscriber;
|
||||||
import org.reactivestreams.Subscription;
|
import org.reactivestreams.Subscription;
|
||||||
import reactor.core.publisher.Operators;
|
import reactor.core.publisher.Operators;
|
||||||
|
|
||||||
|
import org.springframework.core.log.LogDelegateFactory;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.log.LogUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for {@code Publisher} implementations that bridge between
|
* Abstract base class for {@code Publisher} implementations that bridge between
|
||||||
|
@ -49,12 +49,12 @@ public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special logger for debugging Reactive Streams signals.
|
* Special logger for debugging Reactive Streams signals.
|
||||||
* @see LogUtils#getHiddenLog(Class)
|
* @see LogDelegateFactory#getHiddenLog(Class)
|
||||||
* @see AbstractListenerWriteProcessor#rsWriteLogger
|
* @see AbstractListenerWriteProcessor#rsWriteLogger
|
||||||
* @see AbstractListenerWriteFlushProcessor#rsWriteFlushLogger
|
* @see AbstractListenerWriteFlushProcessor#rsWriteFlushLogger
|
||||||
* @see WriteResultPublisher#rsWriteResultLogger
|
* @see WriteResultPublisher#rsWriteResultLogger
|
||||||
*/
|
*/
|
||||||
protected static Log rsReadLogger = LogUtils.getHiddenLog(AbstractListenerReadPublisher.class);
|
protected static Log rsReadLogger = LogDelegateFactory.getHiddenLog(AbstractListenerReadPublisher.class);
|
||||||
|
|
||||||
|
|
||||||
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);
|
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);
|
||||||
|
|
|
@ -25,9 +25,9 @@ import org.reactivestreams.Publisher;
|
||||||
import org.reactivestreams.Subscriber;
|
import org.reactivestreams.Subscriber;
|
||||||
import org.reactivestreams.Subscription;
|
import org.reactivestreams.Subscription;
|
||||||
|
|
||||||
|
import org.springframework.core.log.LogDelegateFactory;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.log.LogUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An alternative to {@link AbstractListenerWriteProcessor} but instead writing
|
* An alternative to {@link AbstractListenerWriteProcessor} but instead writing
|
||||||
|
@ -44,12 +44,12 @@ public abstract class AbstractListenerWriteFlushProcessor<T> implements Processo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special logger for debugging Reactive Streams signals.
|
* Special logger for debugging Reactive Streams signals.
|
||||||
* @see LogUtils#getHiddenLog(Class)
|
* @see LogDelegateFactory#getHiddenLog(Class)
|
||||||
* @see AbstractListenerReadPublisher#rsReadLogger
|
* @see AbstractListenerReadPublisher#rsReadLogger
|
||||||
* @see AbstractListenerWriteProcessor#rsWriteLogger
|
* @see AbstractListenerWriteProcessor#rsWriteLogger
|
||||||
* @see WriteResultPublisher#rsWriteResultLogger
|
* @see WriteResultPublisher#rsWriteResultLogger
|
||||||
*/
|
*/
|
||||||
protected static final Log rsWriteFlushLogger = LogUtils.getHiddenLog(AbstractListenerWriteFlushProcessor.class);
|
protected static final Log rsWriteFlushLogger = LogDelegateFactory.getHiddenLog(AbstractListenerWriteFlushProcessor.class);
|
||||||
|
|
||||||
|
|
||||||
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);
|
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);
|
||||||
|
|
|
@ -24,9 +24,9 @@ import org.reactivestreams.Processor;
|
||||||
import org.reactivestreams.Subscriber;
|
import org.reactivestreams.Subscriber;
|
||||||
import org.reactivestreams.Subscription;
|
import org.reactivestreams.Subscription;
|
||||||
|
|
||||||
|
import org.springframework.core.log.LogDelegateFactory;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.log.LogUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for {@code Processor} implementations that bridge between
|
* Abstract base class for {@code Processor} implementations that bridge between
|
||||||
|
@ -46,12 +46,12 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special logger for debugging Reactive Streams signals.
|
* Special logger for debugging Reactive Streams signals.
|
||||||
* @see LogUtils#getHiddenLog(Class)
|
* @see LogDelegateFactory#getHiddenLog(Class)
|
||||||
* @see AbstractListenerReadPublisher#rsReadLogger
|
* @see AbstractListenerReadPublisher#rsReadLogger
|
||||||
* @see AbstractListenerWriteFlushProcessor#rsWriteFlushLogger
|
* @see AbstractListenerWriteFlushProcessor#rsWriteFlushLogger
|
||||||
* @see WriteResultPublisher#rsWriteResultLogger
|
* @see WriteResultPublisher#rsWriteResultLogger
|
||||||
*/
|
*/
|
||||||
protected static final Log rsWriteLogger = LogUtils.getHiddenLog(AbstractListenerWriteProcessor.class);
|
protected static final Log rsWriteLogger = LogDelegateFactory.getHiddenLog(AbstractListenerWriteProcessor.class);
|
||||||
|
|
||||||
|
|
||||||
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);
|
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -24,9 +24,9 @@ import org.reactivestreams.Subscriber;
|
||||||
import org.reactivestreams.Subscription;
|
import org.reactivestreams.Subscription;
|
||||||
import reactor.core.publisher.Operators;
|
import reactor.core.publisher.Operators;
|
||||||
|
|
||||||
|
import org.springframework.core.log.LogDelegateFactory;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.log.LogUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publisher returned from {@link ServerHttpResponse#writeWith(Publisher)}.
|
* Publisher returned from {@link ServerHttpResponse#writeWith(Publisher)}.
|
||||||
|
@ -40,12 +40,12 @@ class WriteResultPublisher implements Publisher<Void> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special logger for debugging Reactive Streams signals.
|
* Special logger for debugging Reactive Streams signals.
|
||||||
* @see LogUtils#getHiddenLog(Class)
|
* @see LogDelegateFactory#getHiddenLog(Class)
|
||||||
* @see AbstractListenerReadPublisher#rsReadLogger
|
* @see AbstractListenerReadPublisher#rsReadLogger
|
||||||
* @see AbstractListenerWriteProcessor#rsWriteLogger
|
* @see AbstractListenerWriteProcessor#rsWriteLogger
|
||||||
* @see AbstractListenerWriteFlushProcessor#rsWriteFlushLogger
|
* @see AbstractListenerWriteFlushProcessor#rsWriteFlushLogger
|
||||||
*/
|
*/
|
||||||
private static final Log rsWriteResultLogger = LogUtils.getHiddenLog(WriteResultPublisher.class);
|
private static final Log rsWriteResultLogger = LogDelegateFactory.getHiddenLog(WriteResultPublisher.class);
|
||||||
|
|
||||||
|
|
||||||
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);
|
private final AtomicReference<State> state = new AtomicReference<>(State.UNSUBSCRIBED);
|
||||||
|
|
Loading…
Reference in New Issue