How to use log4j in eclipse rcp

How to use log4j logging API in eclipse rcp project? As a workaround, I tried to create a new OSGI Bundle package with log4j banks, the structure of the package is presented below.

log4j an external plugin

I crashed a basic RCP application with a view (template) called loggingtest . I included the log4j package in the dependencies tab of the loggingtest project. activator start method I posted the following code

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

so everything is still fine. I can use the log4j API halfway, I was puzzled by where to put the log4j.properties file, how can I continue to get the log file with all the log statements.

more precisely below - the contents of my loggingtest project manifest file

 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 
+7
source share
3 answers

There is a publication of instructions for setting up Log4J in an OSGi environment. Also consider using Pax Logging with OSGi.

+5
source

I am using log4j with my RCP application
here's what you need to do: just open the log4j plugin (you can get the "osgified" version from the Spring Bundle Repository) and then drop it into the "dropin" folder of your eclipse installation.
then you should add this plugin as a dependency of your application and your Activator class, follow these steps:
URL confURL = getBundle().getEntry("log4j.properties"); PropertyConfigurator.configure(FileLocator.toFileURL(confURL).getFile());

and drop this "log4j.properties" into the root folder of your application
sorry for my English

+3
source
  • Add the log4j.jar project to the project.
  • Add the link to MANIFEST.MF. Require-Bundle: org.apache.log4j;bundle-version="1.2.15"
  • Add the link to build.properties.

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

  1. Use logger in .java files.

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

I found this tutorial useful. Check - Add log4j to RCP application

0
source

All Articles