0

I am using dropwizard 1.3.X and am trying to attach a unique correlation id generated in my servlet filter to my access logs.

I have tried several approaches but my access log still looks like this

127.0.0.1 - - [20/Aug/2020:18:15:56 +0000] "GET /v1/ HTTP/1.1" 404 43 "-" "RxNetty Client" 12

Is it possible for me to somehow override the default logging of dropwizard and attach custom attributes from the header?

I looked at the solution offered Here, but it seems to be outdated and RequestLogFactory is now an interface. I am not sure if implementing it would be the right thing to do.

my yaml config file looks like this:

server:
  type: 
  applicationContextPath: /
  adminContextPath: /
  connector:
    type: 
    port: 
logging:
    level: INFO
    appenders:
    - type: console
      threshold: ALL
      target: stdout
      logFormat: "%d{dd/MMM/yyyy:HH:mm:ss} [%thread] %X{Correlation-ID} %-5level %logger{36} - %msg%n"
hal9000
  • 201
  • 5
  • 25

1 Answers1

0

We've overridden the request log with similar requirements here (we also filter out certain requests from the log, and the code is in kotlin instead of java, fwiw): https://github.com/trib3/leakycauldron/blob/main/server/src/main/kotlin/com/trib3/server/config/dropwizard/FilteredLogbackAccessRequestLogFactory.kt

We then activate it in dropwizard config by specifying

server:
  requestLog:
     type: filtered-logback-access
Joe
  • 607
  • 6
  • 13