Spring Integration DSL:在AbstractMessageHandler中禁用双重DEBUG日志记录

时间:2018-01-19 10:28:29

标签: spring spring-integration spring-integration-dsl

我使用Spring Integration DSL的.log()函数,我想在DEBUG级别创建一个日志。这是一个例子:

...
.<DataDTO>log(LoggingHandler.Level.DEBUG, "Http Input Flow V2",          
              message -> {
                 DataDTO dto = message.getPayload();
                 return "Input data: " + dto.toString;
              })
...

但是,这有效,会创建两条日志消息:实际日志消息Input data: ...AbstractMessageHandler中的消息:

@Override
public void handleMessage(Message<?> message) {
    ...
    if (this.loggingEnabled && this.logger.isDebugEnabled()) {
        this.logger.debug(this + " received message: " + message);
    }
    ...
 }

AbstractMessageHandler中,this.loggingEnabled默认设置为true

是否可以禁用AbstractMessageHandler中的日志记录,但保留自定义日志消息?我尝试将AbstractMessageHandler中的application.yml的日志记录级别设置为ERROR,但这没有帮助。

1 个答案:

答案 0 :(得分:1)

我认为你的日志配置中有org.springframework.integration=DEBUG甚至org.springframework=DEBUG

文字"Http Input Flow V2"对于该类别来说有点尴尬:

   /**
     * Populate a {@link WireTap} for the {@link #currentMessageChannel}
     * with the {@link LoggingHandler} subscriber for the provided
     * {@link LoggingHandler.Level} logging level, logging category
     * and {@link Function} for the log message.
     * @param level the {@link LoggingHandler.Level}.
     * @param category the logging category.
     * @param function the function to evaluate logger message at runtime
     * @param <P> the expected payload type.
     * against the request {@link Message}.
     * @return the current {@link IntegrationFlowDefinition}.
     * @see #wireTap(WireTapSpec)
     */
    public <P> B log(LoggingHandler.Level level, String category, Function<Message<P>, Object> function) {

loggingEnabled及其代码{/ 1>}可以禁用@EnableIntegrationManagement

/**
 * Use to disable all logging in the main message flow in framework components. When 'false', such logging will be
 * skipped, regardless of logging level. When 'true', the logging is controlled as normal by the logging
 * subsystem log level configuration.
 * <p>
 * It has been found that in high-volume messaging environments, calls to methods such as
 * {@code logger.isDebuggingEnabled()} can be quite expensive and account for an inordinate amount of CPU
 * time.
 * <p>
 * Set this to false to disable logging by default in all framework components that implement
 * {@link IntegrationManagement} (channels, message handlers etc). This turns off logging such as
 * "PreSend on channel", "Received message" etc.
 * <p>
 * After the context is initialized, individual components can have their setting changed by invoking
 * {@link IntegrationManagement#setLoggingEnabled(boolean)}.
 * @return the value; true by default.
 */
String defaultLoggingEnabled() default "true";

falsehttps://docs.spring.io/spring-integration/docs/5.0.0.RELEASE/reference/html/system-management-chapter.html#_configuring_metrics_capture