How to log JSON responses in Dropwizard (Jersey)

Dale Wijnand picture Dale Wijnand · Jun 20, 2013 · Viewed 8k times · Source

I would like to know how one would configure Dropwizard to log the JSON response.

Answer

Dale Wijnand picture Dale Wijnand · Jun 21, 2013

In the Service subclass (ex HelloWorldService), in the run method, add:

environment.setJerseyProperty(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, LoggingFilter.class.getName());
environment.setJerseyProperty(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, LoggingFilter.class.getName());

and then make sure that com.sun.jersey.api.container.filter.LoggingFilter (or any parent package) is configured at least at log level INFO, for example:

logging:
  loggers:
    "com.sun.jersey.api.container.filter.LoggingFilter": INFO