2013-12-23 30 views
2

我有問題配置log4j屬性。
我曾經使用代碼來配置記錄器。
但是,現在我得到了無appender可以發現從groovyx.net.http.RESTClient WARN我不能更改代碼。警告如下:在Intellij中配置log4j.properties

log4j:WARN No appenders could be found for logger (groovyx.net.http.RESTClient). 
log4j:WARN Please initialize the log4j system properly. 

所以我試圖使用log4j.properties文件默認情況下設置appender。但是,我不知道應該在哪裏放置log4j.properties文件。我將-Dlog4j.debug添加爲JVM選項並運行測試。我收到以下信息:

log4j: Trying to find [log4j.xml] using context classloader [email protected] 
log4j: Trying to find [log4j.xml] using [email protected] class loader. 
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource(). 
log4j: Trying to find [log4j.properties] using context classloader [email protected] 
log4j: Trying to find [log4j.properties] using [email protected] class loader. 
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource(). 
log4j: Could not find resource: [null]. 

我正在使用IntelliJ並運行Spock測試。 任何答案將不勝感激。謝謝。

回答

2

你的log4j配置文件應該放在源代碼根目錄下。

在想法它可能是資源文件夾。

看:Where should I put the log4j.properties file?

對Groovy這一切一樣。

+0

很酷。我把它放在資源和它的工作。我正在從其他地方閱讀,說它需要在源/測試源下,這似乎是不正確的。謝謝。 – user1947415

+0

@ user1947415如果您有單獨的測試環境日誌配置,則可以在測試文件夾中配置test-config。隨你便。 – Seagull

+0

是的,文件夾名稱無關緊要。重點是將其標記爲IntelliJ中的資源非源代碼。在發佈此問題之前,我已嘗試將包含log4j.properties文件的文件夾標記爲源和測試源。但是,這是行不通的。 – user1947415