Java - Dropwizard http request accessing log customizing example

less than 1 minute read

Dropwizard can allow to access the attributes in a request as shown in below example.
Full layout logback format details can be found from http://logback.qos.ch/manual/layouts.html

1
2
3
4
5
6
7
8
9
10
server:
  rootPath: /test/services/rest
  requestLog:
    appenders:
    - type: file
      currentLogFilename: ./logs/requests.log
      archivedLogFilenamePattern: ./logs/requests-%d.log
      archivedFileCount: 5
      timeZone: UTC
      logFormat: "%h %l %u [%t{dd/MMM/yyyy:HH:mm:ss Z,UTC}] %reqAttribute{attributeName} \"%r\" %s %b \"%i{Referer}\" \"%i{User-Agent}\" %D"