0

I'm using the .log() function from Spring Integration DSL and I want to create a log at the DEBUG level. Here is an example:

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

This works, however, two logging messages are created: the actual logging message Input data: ... and the one from the AbstractMessageHandler:

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

In AbstractMessageHandler, this.loggingEnabled is set to true by default.

Is it possible to disable the logging in the AbstractMessageHandler but keep the custom log message? I've tried to set the logging level for the AbstractMessageHandler in my application.yml to ERROR, but this did not help.

matthjes
  • 671
  • 7
  • 20

1 Answers1

1

I think you have in your logging config something like org.springframework.integration=DEBUG or even org.springframework=DEBUG.

The literal "Http Input Flow V2" is a bit awkward for the category:

   /**
     * 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) {

Also that loggingEnabled can be disabled by the @EnableIntegrationManagement and its:

/**
 * 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";

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

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • I'm not sure what is meant by category. Usually I give my loggern the name of the class. Do you have examples for better categories? – matthjes Jan 19 '18 at 19:39
  • Correct. In most cases it is class name or just package. But anyway any possible string can be a name for the logging category. For example `root` is there. For your use case I would do in the `application.yml`: `logging.level.Http_Input_Flow_V2=DEBUG`. The same string what you have but without whitespaces. Then you will have DEBUG messages in logs only for this part of your application. – Artem Bilan Jan 19 '18 at 19:43