2016-12-01 101 views
0

我該如何在駱駝中啓用http日誌?我正在使用rest-dsl。我想看到的HTTP標題和正文爲每個請求和響應我的代碼:駱駝碼頭組件日誌記錄

restConfiguration() 
       .component("jetty") 
       .host("0.0.0.0") 
       .port(port) 
       .scheme("https") 
       .bindingMode(RestBindingMode.json) 
       .dataFormatProperty("json.in.disableFeatures", "FAIL_ON_UNKNOWN_PROPERTIES") 
       .dataFormatProperty("json.in.enableFeatures", "FAIL_ON_NULL_FOR_PRIMITIVES") 
       .componentProperty("sslKeyPassword", KEYSTORE_PASSWORD) 
       .componentProperty("sslKeystore", KEYSTORE) 
       .componentProperty("sslPassword", KEYSTORE_PASSWORD) 
       .enableCORS(true) 
       .componentProperty("traceEnabled", "true") 
       // swagger 
       .apiContextPath("api-doc") 
      .apiProperty("api.title", "Mobile Api").apiProperty("api.version", "v1.0") 
      .apiProperty("schemes", "https") 
      ; 

rest(MOBILE_API_PATH).produces("application/json").consumes("application/json") 

      .post("/transaction").type(MobileTransactionRequest.class).outType(MobileTransactionResponse.class) 
      .to("direct:mobileTransaction") 

回答

1

要啓用日誌記錄組件,您需要創建這個豆:

<bean id="log" class="org.eclipse.jetty.server.handler.RequestLogHandler"> 
    <property name="requestLog" ref="jettyLog"/> 
</bean> 
<bean id="jettyLog" class="org.eclipse.jetty.server.Slf4jRequestLog"/> 

並且像這樣配置enpoint:

jetty:http://0.0.0.0:8040/test?handlers=#log 

但默認情況下,記錄器不會寫入主體和所有標題。您應該使用自己的日誌邏輯創建擴展AbstractLifeCycle的類並實現RequestLog。