Adding custom header in dropwizard access logs

47 views Asked by At

How can we customise dropwizard's default access log format. I want to include a header that comes in request to my access log file.

1

There are 1 answers

0
best wishes On

You can use the below configuration to add custom header in access log

          requestLog:
            # type: classic <- removing these are imp
            # timeZone: IST <- removing these are imp
            appenders:
              - type: file
                currentLogFilename: /usr/share/app/logs/access.log
                archivedLogFilenamePattern: /usr/share/app/logs/access-%i.log
                archivedFileCount: 2
                maxFileSize: 200MB
                logFormat: \"%i{x-forwarded-for} %l %u [%t] %r %s %b %i{Referer} %i{User-Agent} %D\"

in the above example we have logged x-forwarded-for, Referer, User-Agent headers. sample of the access log is

10.49.3.116 - - [11/Oct/2023:05:42:56 +0000] POST /v2/url?url_converted=false HTTP/1.1 200 525 - curl/7.52.1 22