兩個問題/問題:自動log4j的配置和bundleresource
1)在很多人的log4j線程/論壇/等等,我看到定義包含前綴log4j的配置文件中引用log4j.debug的結果「文件:」如下圖所示:
log4j: Using URL [file:/data/app/conf/log4j.properties] for automatic log4j configuration.
在我更新的代碼(其他開發人員編寫的工作現在別的地方),我看到:
log4j: Using URL [bundleresource://23/log4j.properties] for automatic log4j configuration
上面顯示的「bundleresource」在哪裏?我認爲這是我一直無法識別的專用資源Eclipse插件。
2)這個問題源於一個更大的問題,如果沒有顯式地將其插入到JVM的命令行參數中(例如-Dlog4j.configuration),則無法加載log4j配置文件。我正在替換測試服務器上的基於Eclipse插件的應用程序,該應用程序沒有在啓動腳本中指定的此命令行參數,並且能夠在正確初始化log4j的情況下正確啓動。當我用我們的源代碼庫中的最新版本替換這個應用程序時,應用程序無法找到log4j配置文件。想知道爲什麼第一個應用程序可以啓動並找到log4j配置文件,而第二個(較新的)應用程序不能?
任何幫助將不勝感激。
謝謝!定義
更新/編輯
從與log4j.debug應用輸出:
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].
我會這樣做,但是在對源代碼進行掃描之後,PropertyConfigurator或DocumentConfigurator都不會顯式調用。這一切似乎都是在上次安裝時自動啓動完成的。它似乎是在類路徑中找到log4j配置,找到了我不知道的地方。有關於此的任何其他想法? – Michael
這個問題確實是由於在類路徑中找不到log4j配置文件造成的。我將在後續編輯中發佈我的輸出。 – Michael
我至少回答了問題2. = D我從來沒有使用classpath log4j的東西,我只是使用我發佈的答案。也許,在您的主要鉤子上,您可以從已知位置加載屬性文件並將其添加到您的jar路徑,並從您的類加載器加載。 – Nthalk