2011-11-03 43 views
7

如何在eclipse rcp項目中使用log4j logging API?作爲一種解決方法,我嘗試創建一個具有log4j jar的新OSGI Bundle,下面是bundle結構。如何在eclipse rcp中使用log4j

log4j an external plugin

我裝箱,以期(模板)命名loggingtest .I've基本RCP應用程序包含在loggingtest project.In活化劑的依賴性選項卡捆綁的log4j啓動方法我把下面的代碼

Logger logger = Logger.getLogger(Activator.class); 
logger.info("Info starting"); 
logger.warn("Warning starting"); 
logger.error("Error starting"); 

所以一切都很好,到目前爲止我能使用log4j的API,並完成了一半,我感到不解的地方放置log4j.prope rties文件,我如何繼續進一步獲取所有日誌語句的日誌文件。

更精確下面是我的清單文件的loggingtest項目

Manifest-Version: 1.0 
Bundle-ManifestVersion: 2 
Bundle-Name: LoggingTest 
Bundle-SymbolicName: LoggingTest; singleton:=true 
Bundle-Version: 1.0.0.qualifier 
Bundle-Activator: loggingtest.Activator 
Require-Bundle: org.eclipse.ui, 
org.eclipse.core.runtime, 
log4j;bundle-version="1.0.0" 
Bundle-ActivationPolicy: lazy 
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 
+0

只要有人不依賴於log4j,Eclipse RCP就會提供自己的日誌工具 - https://wiki.eclipse.org/FAQ_How_do_I_use_the_platform_logging_facility%3F,它可以讓您在Eclipse平臺上工作而無需手動入侵。 –

回答

5

的內容有一個posting如何對設置Log4J的在OSGi的環境。在使用OSGi時,請考慮使用Pax Logging。

+1

跟在IDE中運行的相同文章相當不錯,當我嘗試導出產品時無法生成日誌文件 – srk

+0

使用-console啓動產品,並通過OSGi-console檢查日誌包和碎片是否已加載並啓動... –

+1

我忘了添加lo4j。屬性到二進制構建路徑,並最終它爲我添加後構建路徑,感謝 – srk

3

我使用log4j的與我的RCP應用
這裏是你應該做的:剛落log4j的插件(你可以從春捆綁庫的「osgified」版本),然後拖放到「脫入」文件夾你的eclipse安裝。
那麼,你應該增加這個插件爲您的應用dependencie和你的Activator類,請執行下列操作:
URL confURL = getBundle().getEntry("log4j.properties"); PropertyConfigurator.configure(FileLocator.toFileURL(confURL).getFile());

,並放棄這一「log4j.properties」在您的應用程序
對不起你的根文件夾關於我的英語

0
  1. 在您的項目中添加log4j.jar。
  2. 在MANIFEST.MF中添加參考。 Require-Bundle: org.apache.log4j;bundle-version="1.2.15"
  3. 在build.properties中添加引用。

bin.includes = plugin.xml,\ META-INF/,\ .,\ lib/log4j-1.2.17.jar

  • 使用在.java文件記錄器。
  • PropertyConfigurator.configure(log4jConfPath); LOGGER.debug("STARTING APPLICATION ..");

    我發現這個教程的幫助。請檢查 - Add log4j to RCP Application

    相關問題