如何在 Eclipse RCP 中使用 log4j? [英] How to use log4j in an Eclipse RCP?

查看:19
本文介绍了如何在 Eclipse RCP 中使用 log4j?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Eclipse RCP 项目中使用 log4j 日志 API?

How to use log4j logging API in an Eclipse RCP project?

作为一种解决方法,U 尝试创建一个具有 log4j jar 的新 OSGI Bundle,以下是 bundle 结构:

As a workaround U tried to create a new OSGI Bundle which has a log4j jars, below is the bundle structure:

我已经创建了一个基本的 RCP 应用程序,其中包含一个名为 loggingtest 的视图(模板).我在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 Logging.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆