2017-03-05 67 views
0

我有一個jar,比如a.jar,我只想在INFO級別啓用日誌記錄。這個jar還依賴於另一個jar,比如說b.jar,它使用Apache HTTP客戶端。當我運行我的應用程序,我看到很多調試輸出的屏幕包括僅在這一格式的Apache HTTP客戶端上的東西,不管是什麼,我把在log4j.properties:無法找到使用中的記錄器配置

[com.amazonaws.AmazonWebServiceClient] : Internal logging successfully configured to commons logger: true Ignored FQCN: org.apache.commons.logging.impl.SLF4JLocationAwareLog 

對於生活我,我無法弄清楚罐子的配置來自哪裏。這是我嘗試過的東西。 1.添加一個log4j.properties只a.jar文件的主/資源目錄 2.增加了一個log4j.properties只b.jar的主/資源目錄 3.刪除log4j.properties

請幫我一些輸入日誌配置可能從哪裏獲取。

a.jar文件

<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-api</artifactId> 
    <version>1.7.5</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>log4j</groupId> 
    <artifactId>log4j</artifactId> 
    <version>1.2.15</version> 
    <scope>compile</scope> 
</dependency> 

這裏的

我這裏還有POM提取物是爲b.jar

<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-api</artifactId> 
    <version>1.7.7</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-log4j12</artifactId> 
    <version>1.7.7</version> 
    <scope>compile</scope> 
</dependency> 

回答

0

提取我假設你的意思是this 「Apache HTTP client」?如果是這樣,那麼Log4J的日誌配置不會影響HttpClient的日誌輸出,因爲後者既不使用SLF4J也不使用Log4J。正如你可以從this POM看到的,HttpClient使用Apache Commons Logging來代替它的日誌輸出。

因此,您的目標是通過SLF4J將所有Commons Logging輸出重定向到Log4J。這需要兩個步驟:

  1. 爲Commons Logging添加SLF4J網橋。
  2. 確保網橋用作Commons Logging的替代品。

要添加的橋被描述爲here。爲確保橋樑實際使用,我會建議exclude the original Commons Logging JAR。你應該能夠實現以下新的/更新的依賴兩個步驟爲您的項目B:

<dependency> 
    <groupId>org.apache.httpcomponents</groupId> 
    <artifactId>httpclient</artifactId> 
    <version>4.5.3</version> 
    <exclusions> 
    <exclusion> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
    </exclusion> 
    </exclusions> 
</dependency> 
<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>jcl-over-slf4j</artifactId> 
    <version>1.7.24</version> 
</dependency> 

我已經加入了最新版本SLF4J在24年7月1日橋jcl-over-slf4j,因爲它似乎是你的SLF4J的版本( 1.7.7)似乎不支持Commons Logging 1.2,但是,它可能被HttpClient使用(至少是4.5.3版中的)。

(請注意,我沒有測試過這一點。但是,最終的解決方案至少應該非常相似所描述的方法。)

0

看着this,好像亞馬遜SDK罐子之一是地方此日誌記錄配置將存在於。

它使用apache公共日誌記錄,並且您在項目中正在執行的任何配置都是針對slf4j完成的,因此不會產生任何影響。

相關問題