SpringCloudGateway - Log incoming request url and corresponding route URI

JavaCodeNet picture JavaCodeNet · Jan 9, 2019 · Viewed 8.3k times · Source

I am new to spring cloud gateway, what I want is to log incoming request to corresponding route url, For e.g. if I have following route config:

      - id: route1
        uri: http://localhost:8585/
        predicates:
        - Path=/foo/**
        filters:
        - RewritePath=/foo/(?<segment>.*), /$\{segment}

Then for a incoming request of 'http://localhost:8080/foo/route1' following log message should be printed.

"Incoming request url 'http://localhost:8080/foo/route1' is routed to 'http://localhost:8585/route1'"

Is there any easy way of achieving this or can I achieve this just by setting log level.

Can you please help

Answer

bzhu picture bzhu · Jan 2, 2020

From spring cloud gateway 2.2, please try following switches:

logging:
  level:
    reactor:
      netty: INFO
    org:
      springframework:
        cloud:
          gateway: TRACE
spring:
  cloud:
    gateway:
      httpclient:
        wiretap: true
      httpserver:
        wiretap: true

more info please refer here, spring cloud gateway log levels