如何在Dropwizard(Jersey)中记录JSON响应
问题描述:
我想知道如何配置Dropwizard来记录JSON响应。
I would like to know how one would configure Dropwizard to log the JSON response.
答
在dropwizard 0.8.1中(也尝试在0.9.0-SNAPSHOT),添加到 Application.run(...)
:
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)
);
}
要配置记录器,请添加配置文件(例如: conf.yml
):
To configure logger, add in your configuration file (e.g.:conf.yml
):
logging:
loggers:
org.glassfish.jersey.filter.LoggingFilter: INFO