2017-03-17 6 views
1

は私がとthisを見て、私の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に設定されているため、アプリケーションは何もログに記録しようとせず、java.util.Loggerの方法でLoggerの一部のサブクラスによって上書きされ、レベルがERRORに変更されているを持つfilter implementation of ContainerRequestFilterfilter implementation of ContainerResponseFilterのインターフェイスから戻ります。

私はこの実装の考え方が貧弱だと考えるのは2番目です。同時に、Level.OFFに変更すると、何もログに記録されないことが期待されます。同時に

(少なくともERROR下で)指定された冗長のでHTTPヘッダーならびにテキストメディア タイプの実体内容の全体

コンテンツが記録されLoggingFeature.Verbosity.PAYLOAD_TEXTあります。

これはログの[ERROR]メッセージの後の詳細です。

+1

ありがとうございました。私の頭には「OFF」に設定するとログが生成され、「ALL」に設定すると何も生成されませんでした。 「FINE」を試してみるのは私には起こりませんでした。特定のリクエストが特定のユーザーから呼び出されたときにログを取る方法を理解しようとしています。しかし、説明のためにたくさんありがとう@nullpointer – TheLearner

+0

@ TheLearner私はこれが現在どこに属しているかわからない。しかし、これは関係するライブラリのいずれかに予期しない動作(バグ)として発生するはずです。 – nullpointer

+0

私はそれをできるだけ早く報告する – TheLearner

関連する問題