我在run(Configuration configuration, Environment environment)
方法添加此行Dropwizard Jersey記錄請求/響應爲ERROR,但爲什麼?
environment.jersey().register(new LoggingFeature(Logger
.getLogger(LoggingFeature.class.getName()), Level.OFF,
LoggingFeature.Verbosity.PAYLOAD_TEXT, null));
看着和this
我只得到的東西,在如果Level
設置爲OFF
,我的所有請求/響應消息的日誌記錄爲錯誤,但爲什麼錯誤?
這裏是日誌的例子:
ERROR [11:17:41.603] [dw-31 - GET /helloworld] o.g.j.l.LoggingFeature - 1
* Server has received a request on thread dw-31 - GET /helloworld
1 > GET http://localhost:8080/helloworld
1 > Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
1 > Accept-Encoding: gzip, deflate, sdch, br
1 > Accept-Language: en-US,en;q=0.8
1 > Cache-Control: max-age=0
1 > Connection: keep-alive
1 > Cookie: openid_provider=openid; _ga=GA1.1.1009619719.1483436711
1 > Host: localhost:8080
1 > Upgrade-Insecure-Requests: 1
1 > User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36
ERROR [11:17:41.615] [dw-31 - GET /helloworld] o.g.j.l.LoggingFeature - 1 * Server responded with a response on thread dw-31 - GET /helloworld
1 < 200
我的資源類:
@Path("/helloworld")
@Produces(MediaType.APPLICATION_JSON)
public class HelloWorldResource {
public HelloWorldResource() { }
@GET
public Response helloWorld(){
System.out.println("Hello World");
return Response.ok().build();
}
}
我的主應用程序類:
public class ApiApplication extends Application<ApiConfiguration>{
public static void main(String[] args) throws Exception{
new ApiApplication().run(args);
}
@Override
public void initialize(Bootstrap<ApiConfiguration> bootstrap) {
// nothing to do yet
}
@Override
public void run(ApiConfiguration apiConfiguration, Environment environment) throws Exception {
final TemplateHealthCheck healthCheck =
new TemplateHealthCheck(apiConfiguration.getTemplate());
environment.healthChecks().register("template", healthCheck);
final HelloWorldResource helloWorldResource = new HelloWorldResource();
final JerseyEnvironment jerseyEnvironment = environment.jersey();
jerseyEnvironment.register(helloWorldResource);
jerseyEnvironment.register(new LoggingFeature(Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), Level.OFF, LoggingFeature.Verbosity.PAYLOAD_ANY, Integer.MAX_VALUE));
}
}
感謝它的幫助,以及我不能讓我的頭周圍,日誌產生時設置爲「關」,但沒有產生時,設置爲「全部」。我沒有想到嘗試'FINE'。試圖找出如何記錄從特定用戶調用特定請求的時間。但非常感謝解釋@nullpointer – TheLearner
@TheLearner目前我不太確定這屬於哪裏。但是這應該作爲意外的行爲(bug)引發到所涉及的任何一個庫中。 – nullpointer
我會盡快報告 – TheLearner