[slf4j-user] How to initialize the logging system under OSGi?

Samad Lotia samad.lotia at pasteur.fr
Fri Jul 24 20:24:41 CEST 2009


Hello,

I am wondering how I can setup SLF4J's Log4J backend to use specific
appenders in an OSGi/Spring environment. I have one bundle that adds an
appender when it is started:

import org.apache.log4j.Appender;
import org.apache.log4j.Logger;
...
Logger logger = Logger.getRootLogger();
log.addAppender(myAppender);

Now I obtain a logger from a different bundle, which is done as follows:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
...
Logger logger = LoggerFactory.getLogger(getClass().getName());

Issuing log messages to "logger" will not appear in the appender I specified
in the first bundle. How can I fix this?

I am using these dependencies in Maven for both bundles:
<groupId>org.slf4j</groupId>
<artifactId>com.springsource.slf4j.api</artifactId>
<version>1.5.6</version>

<groupId>org.slf4j</groupId>
<artifactId>com.springsource.slf4j.log4j</artifactId>
<version>1.5.6</version>

Any help would be greatly appreciated!

Samad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/slf4j-user/attachments/20090724/fe3c1971/attachment.htm>


More information about the slf4j-user mailing list