How to use log4j in an Eclipse RCP?
Asked Answered
C

3

7

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

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

log4j an external plugin

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");

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.

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
Capitalist answered 3/11, 2011 at 12:30 Comment(1)
Just if somebody isn't tied to log4j, Eclipse RCP provides its own logging facility - wiki.eclipse.org/… that lets you work within Eclipse platform without manual hacks.Dropkick
U
5

There is a posting how-to setup Log4J in an OSGi-Environment. Also consider using Pax Logging when working with OSGi.

Ultrastructure answered 3/11, 2011 at 12:47 Comment(5)
followed the same posting which works in IDE pretty well,when i try to export product unable to generate a log fileCapitalist
start your product with -console and check via OSGi-console if the logging bundle and fragments are loaded and started...Ultrastructure
I've forgotten to add the lo4j.properties to the binary build path and eventually it worked for me after adding that to build path,gratitudeCapitalist
any one who wants to watch a video tutorial please go to link, I've created a video youtube.com/watch?v=F1t1qxPBfw0&feature=feeduCapitalist
OT: Any recent guide for Pax logging instead?Fuentes
E
3

i'm using log4j with my RCP app
here's what you should do: just drop log4j plugin (you can get the 'osgified' version from Spring Bundle Repository) and then, drop it to the 'dropin' folder of your eclipse installation.
then, you should add this plugin as a dependencie of your app and on your Activator class, do the following:
URL confURL = getBundle().getEntry("log4j.properties"); PropertyConfigurator.configure(FileLocator.toFileURL(confURL).getFile());

and drop this 'log4j.properties' on your root folder of your app
sorry about my english

Embodiment answered 3/11, 2011 at 16:23 Comment(0)
A
0
  1. Add log4j.jar in your project.
  2. Add the reference in MANIFEST.MF. Require-Bundle: org.apache.log4j;bundle-version="1.2.15"
  3. Add the reference in build.properties.

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

  1. Use the logger in .java files.

PropertyConfigurator.configure(log4jConfPath); LOGGER.debug("STARTING APPLICATION ..");

I found this tutorial helpful. Please check - Add log4j to RCP Application

Asare answered 10/2, 2016 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.