[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] Using Log4J in Equinox framework

I think the simplest way you want is to change a log4j Jar file to a log4j bundle. Just create a new bundle project, put log4j.jar in the bundle directory, add log4j.jar to the project build path, export all the packages in log4j.jar,(through Export-Package in bundle's MANIFEST.MF), add log4j to the bundle class path (through Bundle-Classpath in bundle's MANIFEST.MF). And then you get a log4j bundle which can run on Equinox.
You may also use a prebuild bundle from springsource's bundle-repository: http://www.springsource.com/repository/app/search?query=log4j
You want to use log4j APIs, just import log4j package in other bundle (through Import-Package in bundle's MANIFEST.MF) and use it directly. But in this way, loading of the configuration file log4j.properties is a problem. log4j.properties can locate in the jar bundle or use a argument to figure it out.

To work around this, create a new fragment bundle (ex. foo.bar.logging.config), which only contains your log4j.properties file. You need to add the following line to the bundle's manifest:
Fragment-Host: com.springsource.org.apache.log4j.

This makes sure that the log4j.properties file is visible from within the log4j bundle's classloader without "patching" the log4j-bundle's manifest.
In contrast to the equinox buddy-classloading, this is part of the OSGi standard, and therefore will also work in other OSGi frameworks.

Martin Below