diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java index d6d0deb72e..fa8ed9877f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java @@ -50,8 +50,11 @@ import org.springframework.util.ClassUtils; */ public class HandlerMethod { - /** Logger that is available to subclasses. */ - protected final Log logger = LogFactory.getLog(getClass()); + /** Public for wrapping with fallback logger. */ + public static final Log defaultLogger = LogFactory.getLog(HandlerMethod.class); + + + protected Log logger = defaultLogger; private final Object bean; @@ -161,6 +164,24 @@ public class HandlerMethod { return result; } + + /** + * Set an alternative logger to use than the one based on the class name. + * @param logger the logger to use + * @since 5.1 + */ + public void setLogger(Log logger) { + this.logger = logger; + } + + /** + * Return the currently configured Logger. + * @since 5.1 + */ + public Log getLogger() { + return logger; + } + /** * Return the bean for this handler method. */ diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java index 343876f8e0..6f61e716ff 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java @@ -85,6 +85,10 @@ public abstract class AbstractMethodMessageHandler protected final Log logger = LogFactory.getLog(getClass()); + @Nullable + private Log handlerMethodLogger; + + private final List destinationPrefixes = new ArrayList<>(); private final List customArgumentResolvers = new ArrayList<>(4); @@ -232,6 +236,12 @@ public abstract class AbstractMethodMessageHandler if (this.returnValueHandlers.getReturnValueHandlers().isEmpty()) { this.returnValueHandlers.addHandlers(initReturnValueHandlers()); } + Log returnValueLogger = getReturnValueHandlerLogger(); + if (returnValueLogger != null) { + this.returnValueHandlers.setLogger(returnValueLogger); + } + + this.handlerMethodLogger = getHandlerMethodLogger(); ApplicationContext context = getApplicationContext(); if (context == null) { @@ -367,6 +377,24 @@ public abstract class AbstractMethodMessageHandler */ protected abstract Set getDirectLookupDestinations(T mapping); + /** + * Return a logger to set on {@link HandlerMethodReturnValueHandlerComposite}. + * @since 5.1 + */ + @Nullable + protected Log getReturnValueHandlerLogger() { + return null; + } + + /** + * Return a logger to set on {@link InvocableHandlerMethod}. + * @since 5.1 + */ + @Nullable + protected Log getHandlerMethodLogger() { + return null; + } + /** * Subclasses can invoke this method to populate the MessagingAdviceBean cache * (e.g. to support "global" {@code @MessageExceptionHandler}). @@ -514,6 +542,9 @@ public abstract class AbstractMethodMessageHandler } handlerMethod = handlerMethod.createWithResolvedBean(); InvocableHandlerMethod invocable = new InvocableHandlerMethod(handlerMethod); + if (this.handlerMethodLogger != null) { + invocable.setLogger(this.handlerMethodLogger); + } invocable.setMessageMethodArgumentResolvers(this.argumentResolvers); try { Object returnValue = invocable.invoke(message); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java index 5f744a4fda..6b8d701f7f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java @@ -37,11 +37,32 @@ import org.springframework.util.concurrent.ListenableFuture; */ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMethodReturnValueHandler { - private static final Log logger = LogFactory.getLog(HandlerMethodReturnValueHandlerComposite.class); + /** Public for wrapping with fallback logger. */ + public static final Log defaultLogger = LogFactory.getLog(HandlerMethodReturnValueHandlerComposite.class); + + + private Log logger = defaultLogger; private final List returnValueHandlers = new ArrayList<>(); + /** + * Set an alternative logger to use than the one based on the class name. + * @param logger the logger to use + * @since 5.1 + */ + public void setLogger(Log logger) { + this.logger = logger; + } + + /** + * Return the currently configured Logger. + * @since 5.1 + */ + public Log getLogger() { + return logger; + } + /** * Return a read-only list with the configured handlers. */ diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributes.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributes.java index 93f969f937..47a2f485c3 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributes.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributes.java @@ -19,7 +19,6 @@ package org.springframework.messaging.simp; import java.util.Map; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; @@ -46,7 +45,7 @@ public class SimpAttributes { public static final String DESTRUCTION_CALLBACK_NAME_PREFIX = SimpAttributes.class.getName() + ".DESTRUCTION_CALLBACK."; - private static final Log logger = LogFactory.getLog(SimpAttributes.class); + private static final Log logger = SimpLogging.forLogName(SimpAttributes.class); private final String sessionId; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpLogging.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpLogging.java new file mode 100644 index 0000000000..17fd2b54e0 --- /dev/null +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpLogging.java @@ -0,0 +1,68 @@ +/* + * Copyright 2002-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.messaging.simp; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.util.log.LogUtils; + +/** + * Holds the shared logger named "org.springframework.web.SimpLogging" to use + * for STOMP over WebSocket messaging when logging for + * "org.springframework.messaging.simp" is off but logging for + * "org.springframework.web" is on. + * + *

This makes it possible to enable all web related logging via + * "org.springframework.web" including logging from lower-level packages such as + * "org.springframework.messaging.simp". + * + *

To see logging from the primary classes where log messages originate from, + * simply enable logging for "org.springframework.messaging". + * + * @author Rossen Stoyanchev + * @since 5.1 + */ +public abstract class SimpLogging { + + private static final Log fallbackLogger = + LogFactory.getLog("org.springframework.web." + SimpLogging.class.getSimpleName()); + + + /** + * Create a primary logger for the given class and wrap it with a composite + * that delegates to it or to the fallback logger named + * "org.springframework.web.SimpLogging", if the primary is not enabled. + * @param primaryLoggerClass the class for the name of the primary logger + * @return the resulting composite logger + */ + public static Log forLogName(Class primaryLoggerClass) { + Log primaryLogger = LogFactory.getLog(primaryLoggerClass); + return forLog(primaryLogger); + } + + /** + * Wrap the given primary logger with a composite logger that delegates to + * either the primary or to the shared fallback logger + * "org.springframework.web.HttpLogging", if the primary is not enabled. + * @param primaryLogger the primary logger to use + * @return the resulting composite logger + */ + public static Log forLog(Log primaryLogger) { + return LogUtils.getCompositeLog(primaryLogger, fallbackLogger); + } + +} diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java index 95656002e5..4b5aa03c53 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.commons.logging.Log; + import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; @@ -56,8 +58,10 @@ import org.springframework.messaging.handler.invocation.AbstractMethodMessageHan import org.springframework.messaging.handler.invocation.CompletableFutureReturnValueHandler; import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler; +import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandlerComposite; import org.springframework.messaging.handler.invocation.ListenableFutureReturnValueHandler; import org.springframework.messaging.simp.SimpAttributesContextHolder; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageMappingInfo; import org.springframework.messaging.simp.SimpMessageSendingOperations; @@ -357,6 +361,16 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan return handlers; } + @Override + protected Log getReturnValueHandlerLogger() { + return SimpLogging.forLog(HandlerMethodReturnValueHandlerComposite.defaultLogger); + } + + @Override + protected Log getHandlerMethodLogger() { + return SimpLogging.forLog(HandlerMethod.defaultLogger); + } + @Override protected boolean isHandler(Class beanType) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java index bd9f64663c..9ac9299615 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java @@ -17,7 +17,6 @@ package org.springframework.messaging.simp.annotation.support; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.core.MethodParameter; import org.springframework.lang.Nullable; @@ -26,6 +25,7 @@ import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.simp.SimpMessagingTemplate; @@ -58,7 +58,7 @@ import org.springframework.util.Assert; */ public class SubscriptionMethodReturnValueHandler implements HandlerMethodReturnValueHandler { - private static final Log logger = LogFactory.getLog(SubscriptionMethodReturnValueHandler.class); + private static final Log logger = SimpLogging.forLogName(SubscriptionMethodReturnValueHandler.class); private final MessageSendingOperations messagingTemplate; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java index ed22f71446..08621c6e86 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java @@ -21,7 +21,6 @@ import java.util.Collections; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; @@ -31,6 +30,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.SubscribableChannel; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.support.ChannelInterceptor; @@ -48,7 +48,7 @@ import org.springframework.util.CollectionUtils; public abstract class AbstractBrokerMessageHandler implements MessageHandler, ApplicationEventPublisherAware, SmartLifecycle { - protected final Log logger = LogFactory.getLog(getClass()); + protected final Log logger = SimpLogging.forLogName(getClass()); private final SubscribableChannel clientInboundChannel; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java index e12655de4a..83bbbd7d93 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java @@ -17,10 +17,10 @@ package org.springframework.messaging.simp.broker; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; import org.springframework.util.CollectionUtils; @@ -40,7 +40,7 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist private static final MultiValueMap EMPTY_MAP = CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(0)); - protected final Log logger = LogFactory.getLog(getClass()); + protected final Log logger = SimpLogging.forLogName(getClass()); @Override diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java index 149a88e849..26459851d3 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java @@ -37,6 +37,7 @@ import org.springframework.messaging.converter.MessageConverter; import org.springframework.messaging.converter.StringMessageConverter; import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler; import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler; @@ -125,6 +126,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC @Bean public AbstractSubscribableChannel clientInboundChannel() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientInboundChannelExecutor()); + channel.setLogger(SimpLogging.forLog(channel.getLogger())); ChannelRegistration reg = getClientInboundChannelRegistration(); if (reg.hasInterceptors()) { channel.setInterceptors(reg.getInterceptors()); @@ -160,6 +162,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC @Bean public AbstractSubscribableChannel clientOutboundChannel() { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientOutboundChannelExecutor()); + channel.setLogger(SimpLogging.forLog(channel.getLogger())); ChannelRegistration reg = getClientOutboundChannelRegistration(); if (reg.hasInterceptors()) { channel.setInterceptors(reg.getInterceptors()); @@ -198,6 +201,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC ExecutorSubscribableChannel channel = (reg.hasTaskExecutor() ? new ExecutorSubscribableChannel(brokerChannelExecutor()) : new ExecutorSubscribableChannel()); reg.interceptors(new ImmutableMessageChannelInterceptor()); + channel.setLogger(SimpLogging.forLog(channel.getLogger())); channel.setInterceptors(reg.getInterceptors()); return channel; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java index 4db50b96f8..00f31473d3 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java @@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.core.ResolvableType; import org.springframework.lang.Nullable; @@ -38,6 +37,7 @@ import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.converter.MessageConverter; import org.springframework.messaging.converter.SimpleMessageConverter; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.support.MessageBuilder; import org.springframework.messaging.support.MessageHeaderAccessor; import org.springframework.messaging.tcp.TcpConnection; @@ -58,7 +58,7 @@ import org.springframework.util.concurrent.SettableListenableFuture; */ public class DefaultStompSession implements ConnectionHandlingStompSession { - private static final Log logger = LogFactory.getLog(DefaultStompSession.class); + private static final Log logger = SimpLogging.forLogName(DefaultStompSession.class); private static final IdGenerator idGenerator = new AlternativeJdkIdGenerator(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java index 0602db210e..fb4f38bb45 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java @@ -17,6 +17,7 @@ package org.springframework.messaging.simp.stomp; import org.springframework.lang.Nullable; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.tcp.TcpOperations; import org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient; import org.springframework.util.Assert; @@ -46,7 +47,7 @@ public class ReactorNettyTcpStompClient extends StompClientSupport { * @param port the port */ public ReactorNettyTcpStompClient(String host, int port) { - this.tcpClient = new ReactorNettyTcpClient<>(host, port, new StompReactorNettyCodec()); + this.tcpClient = initTcpClient(host, port); } /** @@ -58,6 +59,13 @@ public class ReactorNettyTcpStompClient extends StompClientSupport { this.tcpClient = tcpClient; } + private static ReactorNettyTcpClient initTcpClient(String host, int port) { + ReactorNettyTcpClient client = new ReactorNettyTcpClient<>(host, port, new StompReactorNettyCodec()); + client.setLogger(SimpLogging.forLog(client.getLogger())); + return client; + } + + /** * Connect and notify the given {@link StompSessionHandler} when connected * on the STOMP level. @@ -68,7 +76,6 @@ public class ReactorNettyTcpStompClient extends StompClientSupport { return connect(null, handler); } - /** * An overloaded version of {@link #connect(StompSessionHandler)} that * accepts headers to use for the STOMP CONNECT frame. diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java index 6fbe05c8ad..e009b3c459 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java @@ -32,6 +32,7 @@ import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.SubscribableChannel; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler; @@ -397,12 +398,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler @Override protected void startInternal() { if (this.tcpClient == null) { - StompDecoder decoder = new StompDecoder(); - if (this.headerInitializer != null) { - decoder.setHeaderInitializer(this.headerInitializer); - } - ReactorNettyCodec codec = new StompReactorNettyCodec(decoder); - this.tcpClient = new ReactorNettyTcpClient<>(this.relayHost, this.relayPort, codec); + this.tcpClient = initTcpClient(); } if (logger.isInfoEnabled()) { @@ -430,6 +426,17 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler this.tcpClient.connect(handler, new FixedIntervalReconnectStrategy(5000)); } + private ReactorNettyTcpClient initTcpClient() { + StompDecoder decoder = new StompDecoder(); + if (this.headerInitializer != null) { + decoder.setHeaderInitializer(this.headerInitializer); + } + ReactorNettyCodec codec = new StompReactorNettyCodec(decoder); + ReactorNettyTcpClient client = new ReactorNettyTcpClient<>(this.relayHost, this.relayPort, codec); + client.setLogger(SimpLogging.forLog(client.getLogger())); + return client; + } + @Override protected void stopInternal() { publishBrokerUnavailableEvent(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java index 786a092fb9..685b7ba368 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java @@ -24,10 +24,10 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.support.MessageBuilder; import org.springframework.messaging.support.MessageHeaderInitializer; import org.springframework.messaging.support.NativeMessageHeaderAccessor; @@ -51,7 +51,7 @@ public class StompDecoder { static final byte[] HEARTBEAT_PAYLOAD = new byte[] {'\n'}; - private static final Log logger = LogFactory.getLog(StompDecoder.class); + private static final Log logger = SimpLogging.forLogName(StompDecoder.class); @Nullable private MessageHeaderInitializer headerInitializer; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java index 1a76add64e..1e519b5e1f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java @@ -28,10 +28,10 @@ import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.support.NativeMessageHeaderAccessor; @@ -51,7 +51,7 @@ public class StompEncoder { private static final byte COLON = ':'; - private static final Log logger = LogFactory.getLog(StompEncoder.class); + private static final Log logger = SimpLogging.forLogName(StompEncoder.class); private static final int HEADER_KEY_CACHE_LIMIT = 32; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java index 4ad244b286..7f364b0827 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java @@ -22,11 +22,11 @@ import java.util.HashSet; import java.util.Set; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; import org.springframework.util.Assert; @@ -52,7 +52,7 @@ import org.springframework.util.StringUtils; */ public class DefaultUserDestinationResolver implements UserDestinationResolver { - private static final Log logger = LogFactory.getLog(DefaultUserDestinationResolver.class); + private static final Log logger = SimpLogging.forLogName(DefaultUserDestinationResolver.class); private final SimpUserRegistry userRegistry; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java index 3b3386594d..2644e81037 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationMessageHandler.java @@ -20,7 +20,6 @@ import java.util.Arrays; import java.util.List; import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.context.SmartLifecycle; import org.springframework.lang.Nullable; @@ -30,6 +29,7 @@ import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessagingException; import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.core.MessageSendingOperations; +import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.simp.SimpMessagingTemplate; @@ -50,7 +50,7 @@ import org.springframework.util.StringUtils; */ public class UserDestinationMessageHandler implements MessageHandler, SmartLifecycle { - private static final Log logger = LogFactory.getLog(UserDestinationMessageHandler.class); + private static final Log logger = SimpLogging.forLogName(UserDestinationMessageHandler.class); private final SubscribableChannel clientInboundChannel; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java b/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java index ef325add9f..d1c011587a 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java @@ -40,7 +40,7 @@ import org.springframework.util.ObjectUtils; */ public abstract class AbstractMessageChannel implements MessageChannel, InterceptableChannel, BeanNameAware { - protected final Log logger = LogFactory.getLog(getClass()); + protected Log logger = LogFactory.getLog(getClass()); private final List interceptors = new ArrayList<>(5); @@ -52,6 +52,23 @@ public abstract class AbstractMessageChannel implements MessageChannel, Intercep } + /** + * Set an alternative logger to use than the one based on the class name. + * @param logger the logger to use + * @since 5.1 + */ + public void setLogger(Log logger) { + this.logger = logger; + } + + /** + * Return the currently configured Logger. + * @since 5.1 + */ + public Log getLogger() { + return logger; + } + /** * A message channel uses the bean name primarily for logging purposes. */ diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java index 8de9e99549..d2e66ba5c5 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java @@ -67,10 +67,10 @@ import org.springframework.util.concurrent.SettableListenableFuture; */ public class ReactorNettyTcpClient

implements TcpOperations

{ - private static Log logger = LogFactory.getLog(ReactorNettyTcpClient.class); - private static final int PUBLISH_ON_BUFFER_SIZE = 16; + private Log logger = LogFactory.getLog(ReactorNettyTcpClient.class); + private final TcpClient tcpClient; @@ -138,6 +138,24 @@ public class ReactorNettyTcpClient

implements TcpOperations

{ } + /** + * Set an alternative logger to use than the one based on the class name. + * @param logger the logger to use + * @since 5.1 + */ + public void setLogger(Log logger) { + this.logger = logger; + } + + /** + * Return the currently configured Logger. + * @since 5.1 + */ + public Log getLogger() { + return logger; + } + + @Override public ListenableFuture connect(final TcpConnectionHandler

handler) { Assert.notNull(handler, "TcpConnectionHandler is required");