2014-01-06 64 views
0

我有一些麻煩擺脫由彈簧產生調試消息(類同以下的人;有成千上萬的條目):無法禁用日誌消息

19:58:08.380 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'propertyPlaceholderConfigurer' 
19:58:08.380 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'propertyPlaceholderConfigurer' 
19:58:08.383 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'appConfig' 
19:58:08.383 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'appConfig' 
19:58:08.383 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'appConfig' to allow for resolving potential circular references 
19:58:08.384 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'appConfig' 

在相關的問題,有許多建議涉及log4j,web.xml,....
但是,我沒有使用任何這些 - 我只是實例化一個AnnotationConfigApplicationContext並開始創建bean。

在我的pom.xml文件中,有任何日誌框架的引用 - 我只包括Spring的依賴:

<!-- Spring and Transactions --> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-context</artifactId> 
    <version>${spring-framework.version}</version> 
</dependency> 
<!-- ... --> 
    <artifactId>spring-tx</artifactId> 
    <!-- ... --> 
    <artifactId>spring-boot-starter</artifactId> 
    <!-- ... --> 
    <artifactId>spring-web</artifactId> 
<!-- ... --> 

我讀的地方,春天似乎使用「通用日誌」在默認情況下,該我不成功嘗試使用禁用(如Turn Off Apache Common Logging所示):

System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); 

此外,我試圖通過添加排除公地在我的pom.xml登錄:

<exclusions> 
    <!-- Exclude Commons Logging in favor of SLF4j --> 
    <exclusion> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
    </exclusion> 
</exclusions> 

但是還是沒有運氣。

接下來,我試圖包括對log4j的依賴,希望這會覆蓋默認日誌記錄。由於信息格式保持不變,這種嘗試似乎也不成功。

接下來我可以嘗試什麼?

+0

您使用的配置文件呢? – cxdf

+0

@ c-qjv0xfi:不,所有配置都通過註釋完成。添加一個禁用日誌記錄是否必要? – Matthias

+1

我剛剛發現了一個解決方法:http://stackoverflow.com/a/3838108/232175 – Matthias

回答

1

第一:slf4j在classpath上嗎?

SLF4J是Java的另一個日誌抽象,它也可以和Spring框架一起使用。許多圖書館/產品已切換到slf4j。

在其名稱中是否存在與'slf4j'的任何依賴關係?嘗試使用mvn依賴項:tree -Dverbose = true,然後查看是否出現slf4j。如果是這樣,請查看slf4j網站以獲取有關其設置的更多信息。

第二:使用哪個log4j配置文件?

提示檢測是否使用了log4j,並且如果log4j配置文件位於類路徑的某處: 嘗試將屬性log4j.debug設置爲'true'。

當使用mvn exec:java時,只需將-Dlog4j.debug = true添加到命令行即可。

如果是使用Maven保命插件JUnit測試,嘗試在Surefire插件本身集systemProperties:http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html