Search code examples
spring-integrationspring-integration-dsl

Spring Integration DSL: How can I set the logging.level to DEBUG for .log()


How can I change the logging.level to a level below INFO for the .log() entries ? By default, it seems to log only INFO and above. I'm unable to get it to log DEBUG and TRACE.

I have tried (in application.yml):

logging.level:
  org.springframework.integration: DEBUG
  com.my.namespace: DEBUG

but so far no success. Setting the logging.level for org.springframework.integration to DEBUG does indeed log a whole bunch of DEBUG stuff, but not my own .log() statements.

UPDATE:: I am using .log() like this:

.log(DEBUG, "some category", m -> "print something using: " + m.getPayload())

But when I set the log level to DEBUG, nothing is printed. Only if I use INFO like this:

.log(INFO, "some category", m -> "print something using: " + m.getPayload())

Solution

  • The log() operator is fully based on the LoggingHandler: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#logging-channel-adapter and it is implemented like this:

    public B log() {
        return log(LoggingHandler.Level.INFO);
    }
    

    So, it is an INFO independently of what you have so far in the config.

    So, if you'd like to change some log() operator defaults, you should consider to some its appropriate alternative like the same variant where you can provide a desired level:

    public B log(LoggingHandler.Level level) {
    

    It can be done via eternal configuration, but it is possible only via custom property and some conversion logic like LoggingHandler.Level.valueOf(level.toUpperCase()).

    UPDATE

    To make it visible in logs you must provide that org.springframework.integration: DEBUG because this one is a default category for the LoggingHandler. Or use different log() variant:

    log(LoggingHandler.Level level, String category)

    For example:

    log(LoggingHandler.Level.DEBUG, "my.category")
    

    and provide that category in your logging config. Otherwise it is going to rely on default (root?) level.

    So, according your code in the question it must be like this:

    logging.level:
      com.my.namespace: DEBUG
    

    .log(DEBUG, "com.my.namespace", m -> "print something using: " + m.getPayload())