2017-05-11 10 views
0

私はdropwizardのAPIエンドポイント/ログ経由でログをストリーミングしたいと思います。dropwizardでAPI経由でログを流すには?

それは私が考えたものよりも硬いです。 Dropwizardはconfig.ymlを介して設定を読み込み、その情報を非公開にします。そして、私はすべてを記録するロガーをどこで見つけることができるでしょうか? 何か不足していますか?

これを行う別の方法はありますか?

+0

それはあなたがやりたいです本当に明確ではないでしょうか?出力例を挙げることはできますか? httpを介して接続を開いたままにして、停止せずにログを流出させ続けたいですか?彼の仕事はどのようにして知っていますか? – pandaadb

+0

私がログインしていますと仮定: LINE5 LINE6 line7 ... – user3019766

+0

:私は/ログにプレゼント LINE1 LINE2 LINE3 LINE4 瞬間を、私はの連続ストリームを見たいのですがストリームは本当に問題ではありませんが、私はあなたがこれを正しいもののために使用しているのだろうか?あなたは最終的に達成する必要があるものについて詳しく説明できますか? – pandaadb

答えて

0

これは、ストリーミング例であり、あなたも、ここで、この上に読むことができます:

calling flush() on Jersey StreamingOutput has no effect

そして

Example of using StreamingOutput as Response entity in Jersey

コード:

public class StreamingTest extends io.dropwizard.Application<Configuration> { 

    @Override 
    public void run(Configuration configuration, Environment environment) throws Exception { 
     environment.jersey().property(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 0); 
     environment.jersey().register(Streamer.class); 
    } 

    public static void main(String[] args) throws Exception { 
     new StreamingTest().run("server", "/home/artur/dev/repo/sandbox/src/main/resources/config/test.yaml"); 
    } 

    @Path("/log") 
    public static class Streamer { 

     @GET 
     @Produces("application/octet-stream") 
     public Response test() { 
      return Response.ok(new StreamingOutput() { 
       @Override 

       public void write(OutputStream output) throws IOException, WebApplicationException { 
        while (true) { 
         output.write("Test \n".getBytes()); 
         output.flush(); 

         try { 
          Thread.sleep(1000); // simulate waiting for stream 
         } catch (InterruptedException e) { 
          e.printStackTrace(); 
         } 
        } 
       } 
      }).build(); 
     } 
    } 
} 

あなたが欲しいもの。

いくつかの点evironment.jersey().property(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 0);行が重要です。これは、サーバーに、出力をバッファリングせずに呼び出し元に戻すように指示します。

また、あなたが明示的しかし

output.flush();を呼び出すことにより、出力をフラッシュする必要があり、これは、ログを出荷する間違った方法であると思われます。あなたはlogstashを見たことがありますか?またはログを必要な場所に直接ストリームするネットワークベースのアペンダ?助け

希望、

--artur

関連する問題