Dale Wijnand Dale Wijnand - 1 month ago 33
HTTP Question

How to log JSON responses in Dropwizard (Jersey)

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

Answer

In dropwizard 0.8.1 (also tried in 0.9.0-SNAPSHOT), add to Application.run(...):

import java.util.logging.Logger;
import org.glassfish.jersey.filter.LoggingFilter;
...
public void run(MyApplicationConfiguration conf, Environment env) throws Exception {
    // do your stuff and then add LoggingFilter
    env.jersey().register(new LoggingFilter(
                     Logger.getLogger(LoggingFilter.class.getName()),
                     true)
                 );
}

To configure logger, add in your configuration file (e.g.:conf.yml):

logging:
  loggers:
    org.glassfish.jersey.filter.LoggingFilter: INFO
Comments