如何在Eclipse RCP中使用log4j? [英] How to use log4j in an Eclipse RCP?
问题描述
如何在Eclipse RCP项目中使用log4j日志记录API?
How to use log4j logging API in an Eclipse RCP project?
作为一种解决方法,U试图创建一个新的包含log4j jar的OSGI Bundle,以下是捆绑结构:
As a workaround U tried to create a new OSGI Bundle which has a log4j jars, below is the bundle structure:
我创建了一个具有视图的基本 RCP应用(模板),名为 loggingtest 我将包log4j包含在loggingtest项目的依赖项选项卡中。在Activator启动方法中,我放置了以下代码
I've crated a basic RCP application with a view(template) named loggingtest.I've included the bundle log4j in the dependencies tab of loggingtest project.In the Activator start method i placed the following code
Logger logger = Logger.getLogger(Activator.class);
logger.info("Info starting");
logger.warn("Warning starting");
logger.error("Error starting");
所以到目前为止一切都很好,我可以使用log4j API并通过了一半,困惑于将log4j.properties文件放置在何处,我该如何进一步获取包含所有日志语句的日志文件。
so everything is fine so far I'm able to use log4j API and half way through,i was puzzled as where to place the log4j.properties file,how can i proceed further to get a log file with all log statements.
更准确地说,以下是内容我的loggingtest项目清单文件
to be more precise below is the content of my manifest file of loggingtest project
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
推荐答案
有一个发布如何在OSGi环境中设置Log4J。在使用OSGi时,也请考虑使用Pax日志记录。
There is a posting how-to setup Log4J in an OSGi-Environment. Also consider using Pax Logging when working with OSGi.
这篇关于如何在Eclipse RCP中使用log4j?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!