2017-02-25 50 views
0

我使用了REST自動化框架的球衣客戶v2.25.1這裏是怎麼了登記記錄器和初始化客戶端:Jersey客戶端2.25日誌不是請求/響應交通工作

//Initialize FileHandler 
Path currPath = Paths.get(System.getProperty("user.dir")); 
Path logFilePath = Paths.get(currPath.toString(), "logs", testCaseName+".log"); 
logHandleObj = new FileHandler(logFilePath.toString(), 0, 1, true); 

//Initialize Logger 
Logger loggerObj = Logger.getLogger(testCaseName); 
loggerObj.setUseParentHandlers(false); 
loggerObj.addHandler(logHandleObj); 

//Initialize ClientConfig 
ClientConfig clientConfig = new ClientConfig(); 
//Set configuration features 
clientConfig.register(new JacksonFeature()); 
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); 
clientInstance = ClientBuilder.newClient(clientConfig); 
//Register LoggingFeature 
clientInstance.register(new LoggingFeature(loggerObj, Level.ALL, 
     LoggingFeature.Verbosity.PAYLOAD_ANY, LoggingFeature.DEFAULT_MAX_ENTITY_SIZE)); 

由於每documentation,這是應該記錄整個請求/響應流量,像這樣:

1 May 09, 2016 2:55:33 PM org.glassfish.jersey.logging.LoggingInterceptor log 
2 INFO: 1 * Server has received a request on thread grizzly-http-server-0 
3 1 > GET http://localhost:9998/helloworld 
.... 

但是,我得到:

<?xml version="1.0" encoding="windows-1252" standalone="no"?> 
<!DOCTYPE log SYSTEM "logger.dtd"> 
<log> 
<record> 
    <date>2017-02-25T15:30:06</date> 
    <millis>1488016806253</millis> 
    <sequence>0</sequence> 
    <logger>org.glassfish.jersey.client.JerseyInvocation</logger> 
    <level>WARNING</level> 
    <class>org.glassfish.jersey.client.JerseyInvocation</class> 
    <method>validateHttpMethodAndEntity</method> 
    <thread>1</thread> 
    <message>Entity must not be null for http method PUT.</message> 
</record> 

所以兩個問題在這裏:

  • 沒有得到HTTP流量
  • 格式爲XML出於某種原因,而不是純文本

會很感激有這方面的援助。

回答

0

所以在到處尋找之後,我繼續嘗試所有我能想到的東西,並最終找到了解決方案。

logHandleObj = new FileHandler(logFilePath.toString()); 
A-> SimpleFormatter formatter = new SimpleFormatter(); 

Logger loggerObj = Logger.getLogger(testCaseName); 
A-> logHandleObj.setFormatter(formatter); 
B-> loggerObj.setLevel(Level.FINEST); 
loggerObj.setUseParentHandlers(false); 

添加行標有上述固定用XML格式問題(這很容易),並加入一行標有B固定的問題,在日誌文件中的HTTP流量不上來。

所以最後,Level應明確設置爲FINEST爲此工作,這是無處可查的文檔。 希望這可以幫助別人。