Logging all incoming requests on a Dropwizard server
Recently at work, I was assigned a task to migrate some APIs of an old service to a new service while ensuring backward compatibility and contract consistency with all other external services. To achieve this, we needed all existing API definitions of the current service so that we could write new APIs according to the existing definitions of the old service.
After a quick Google search, I found that Dropwizard uses Jersey for JSON-related operations, and Jersey supports something called a LoggingFilter
for exactly these kinds of use cases.
All I had to do was write a custom LoggingFilter
to log all incoming requests:
environment.jersey().register(
new LoggingFilter(Logger.getLogger("InboundRequestResponse"), 819200)
);