【问题标题】:Spring Integration DSL: Disable double DEBUG logging in AbstractMessageHandlerSpring Integration DSL:在 AbstractMessageHandler 中禁用双重调试日志记录
【发布时间】:2018-01-19 10:28:28
【问题描述】:

我正在使用 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 中的日志记录但保留自定义日志消息?我尝试将application.ymlAbstractMessageHandler 的日志记录级别设置为ERROR,但这没有帮助。

【问题讨论】:

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


    【解决方案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 可以被@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

    【讨论】:

    • 我不确定类别是什么意思。通常我给我的记录器类的名称。你有更好类别的例子吗?
    • 正确。在大多数情况下,它是类名或只是包。但无论如何,任何可能的字符串都可以是日志类别的名称。例如root 就在那里。对于您的用例,我会在application.yml:logging.level.Http_Input_Flow_V2=DEBUG 中做。您拥有的相同字符串但没有空格。然后,您将在日志中仅包含应用程序这一部分的 DEBUG 消息。
    猜你喜欢
    • 1970-01-01
    • 2019-01-09
    • 2012-01-24
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 2023-03-20
    相关资源
    最近更新 更多