Jersey Dropwizard将请求/响应记录为错误,但为什么?

Jersey Dropwizard将请求/响应记录为错误,但为什么?,jersey,dropwizard,java.util.logging,Jersey,Dropwizard,Java.util.logging,我添加了这一行 environment.jersey().register(new LoggingFeature(Logger .getLogger(LoggingFeature.class.getName()), Level.OFF, LoggingFeature.Verbosity.PAYLOAD_TEXT, null)); 在我的运行(配置,环境)方法中查看和 只有当级别设置为关闭并且我的所有请求/响应消息都记录为错误时,我才会在日志中获取内容,但为什么会出

我添加了这一行

environment.jersey().register(new LoggingFeature(Logger
    .getLogger(LoggingFeature.class.getName()), Level.OFF, 
          LoggingFeature.Verbosity.PAYLOAD_TEXT, null));
在我的
运行(配置,环境)
方法中查看和

只有当
级别
设置为
关闭
并且我的所有请求/响应消息都记录为错误时,我才会在日志中获取内容,但为什么会出错

以下是日志的一个示例:

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
我的主要应用类:

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));

    }
}
公共类应用程序扩展应用程序{
公共静态void main(字符串[]args)引发异常{
新建应用程序().run(args);
}
@凌驾
公共无效初始化(引导引导引导){
//还没什么要做的
}
@凌驾
公共无效运行(ApiConfiguration ApiConfiguration,Environment)引发异常{
最终模板healthCheck healthCheck=
新模板healthcheck(apiConfiguration.getTemplate());
environment.healthChecks().register(“模板”,healthCheck);
最终HelloWorldResource HelloWorldResource=新HelloWorldResource();
final jersey environment jersey environment=environment.jersey();
jerseyEnvironment.注册(helloWorldResource);
jerseyEnvironment.register(新的LoggingFeature(Logger.getLogger(LoggingFeature.DEFAULT_Logger_NAME))、Level.OFF、LoggingFeature.Verbosity.PAYLOAD_ANY、Integer.MAX_值);
}
}

您应尝试将
记录功能更改为-

environment.jersey().register(new LoggingFeature(
      Logger.getLogger(LoggingFeature.class.getName()), Level.FINE,
             LoggingFeature.Verbosity.PAYLOAD_TEXT, null));
因为当前日志记录设置为
级别.OFF
。应用程序不尝试记录任何内容,并从和接口返回,其中该方法被
Logger
的某个子类覆盖,该子类将级别修改为错误

我认为这一执行被认为是糟糕的。同时希望更改为
Level.OFF
不会记录任何内容。(至少不在
错误
下)

同时,所指定的详细程度也是如此

HTTP头的内容以及文本媒体的实体内容 类型被记录


这是日志中您的[ERROR]消息之后的详细信息。

谢谢它的帮助,我也无法理解日志是在设置为
关闭时生成的,但在设置为
全部时没有生成任何内容。我没有想到要试试
好的
。只是想弄清楚当从给定用户调用特定请求时如何记录。但是非常感谢你的解释@nullpointer@TheLearner我现在不太清楚这是属于哪里的。但这应该作为意外行为(bug)提交给相关的任何一个库。我会尽快报告它
environment.jersey().register(new LoggingFeature(
      Logger.getLogger(LoggingFeature.class.getName()), Level.FINE,
             LoggingFeature.Verbosity.PAYLOAD_TEXT, null));