2017-03-17 4 views
1

나는 thisthis보고 내 run(Configuration configuration, Environment environment) 방법이 라인Dropwizard 저지 요청/응답을 ERROR로 기록하지만 그 이유는 무엇입니까?

environment.jersey().register(new LoggingFeature(Logger 
    .getLogger(LoggingFeature.class.getName()), Level.OFF, 
      LoggingFeature.Verbosity.PAYLOAD_TEXT, null)); 

추가 한

나는 단지 LevelOFF로 설정되어 있고 내 모든 요청/응답 메시지 인 경우 로그에 물건을 얻고있다 ERROR로 기록되었지만 왜 ERROR입니까?

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

    } 
} 

답변

2

당신은 LoggingFeature로 변경하려고 할 것이다 -

environment.jersey().register(new LoggingFeature(
     Logger.getLogger(LoggingFeature.class.getName()), Level.FINE, 
      LoggingFeature.Verbosity.PAYLOAD_TEXT, null)); 

현재 로깅이 Level.OFF으로 설정되었으므로 응용 프로그램에서는 아무 것도 기록하지 않으므로 log(LogRecord) 메서드가 Logger의 하위 클래스에 의해 재정의되어 오류 수준으로 수정되는 java.util.Logger이있는 및 filter implementation of ContainerResponseFilter 인터페이스에서 반환됩니다.

나는이 구현의 생각이 두 번째로 빈약하다고 생각할 것이다. 동시에 Level.OFF으로 변경하면 아무 것도 기록하지 않아야합니다. 동시에

(적어도 ERROR 아래) 지정된 상세 그래서 HTTP 헤더뿐만 아니라 텍스트 미디어 유형의 엔티티 내용의 전체

내용이 기록됩니다 LoggingFeature.Verbosity.PAYLOAD_TEXT입니다.

이것은 [ERROR] 메시지 이후의 세부 정보입니다.

+1

덕분에 도움이되었습니다. 로그가 "꺼짐"으로 설정되었을 때 로그가 생성되었지만 "모두"로 설정되면 아무 것도 생성되지 않았 음을 알 수 없었습니다. 'FINE'을 시험해 본 것은 나에게는 일어나지 않았다. 특정 사용자가 특정 요청을 호출 할 때 로그하는 방법을 파악하려고합니다. 그러나 설명에 많은 감사를드립니다. @nullpointer – TheLearner

+0

@ TheLearner 저는 이것이 현재 어디에 속해 있는지 잘 모르겠습니다. 그러나 이것은 관련된 라이브러리 중 하나에 예기치 않은 동작 (버그)으로 제기되어야합니다. – nullpointer

+0

나는 그것이 가능한 빨리보고 할 것이다. – TheLearner