我有一個項目a-conf
與src/main/resources/logback/conf/a/CommonAppenders.xml
文件:的logback包括片段在OSGi容器
<included>
<appender name="FILE" class="FileAppender" />
</included>
而且我還有一個項目a-runable
與logback.xml
配置其中進口CommonAppenders.xml
:
<configuration>
<!-- this is classpath import -->
<include resource="logback/conf/a/CommonAppenders.xml" />
...
</configuration>
我可以在編譯a-runable
包含所有依賴關係的獨立jar(a-conf
就是其中之一)或作爲OSGi包。當我運行獨立應用程序時,一切正常 - 日誌文件出現在CommonAppenders.xml
中。但是當我運行OSGi容器時,沒有創建日誌文件。我認爲logback不能包含來自classpath的資源,因爲OSGi容器中的每個bundle都有它自己的類加載器(logback使用ClassLoader.getResource()
來包含文件)。
我檢查過Export-Package: logback.conf.a
a-conf.jar/META-INF/MANIFEST.MF
(這是通過maven bundlor插件完成的) - 沒關係。添加Import-Package: logback.conf.a
到a-runable
無效。
我不知道我能做什麼(無需更改代碼,只是配置)。任何幫助將受到歡迎。
P.S.我發現類似的問題here,但logback.xml
已經在類路徑中,它自己的appender工作正常。另外我在現有的日誌中沒有任何FileNotFoundException
。
非常感謝!製作一個可運行的片段確實有幫助! – madhead