2017-09-01 194 views
1

我正在使用Jersey 2.25.1客戶端,並且無法獲取任何日誌輸出。我已經看過了2.25.1文檔 - https://www.scribd.com/document/350321996/Jersey-Documentation-2-25-1-User-Guide - 跟着他們爲客戶記錄描述了 -Jersey 2.25.1客戶端記錄示例

ClientConfig clientConfig = new ClientConfig(); 
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY_CLIENT, LoggingFeature.Verbosity.PAYLOAD_ANY); 
Client client = ClientBuilder.newClient(clientConfig); 

有沒有,我很想念添加步驟?請求按預期工作。該應用程序在Glassfish服務器上運行並使用SLF4J。我的理解是,輸出將記錄到server.log。

+0

您的客戶端應用程序'Glassfish'服務器並使用'SLF4j'上運行? –

回答

0

您還需要註冊一個日誌過濾

clientConfig.register(new MyLogFilter());

您需要創建一個日誌過濾

class MyLogFilter implements ClientRequestFilter { 
    private static final Logger LOG = Logger.getLogger(MyLogFilter.class.getName()); 

    @Override 
    public void filter(ClientRequestContext requestContext) throws IOException { 
     LOG.log(Level.INFO, requestContext.getEntity().toString()); // you can configure logging level here 
    } 
}