I’ve previously implemented OSGI logging to files, using slf4j-api, logback-core and logback-classic bundles.
I’d now like to intercept log calls in a seperate bundle (to show them in a webpage servlet). This tutorial at this blog suggested building a custom implementation of org.slf4j.impl to pass on the messages to the log service. (This worked great!)
The problem I have is that I’d also like to save log messages to a file using logback and our custom implementation of org.slf4j.impl is a bundle in OSGI preventing the logback implementation of org.slf4j.impl being used.
I think this may be because in the tutorial the custom implementation of org.slf4j.impl and slf4j-api are embedded as dependencies and not installed as bundles. However when I try this with
<Embed-Dependency>slf4j.api_1.7.2.jar, logbackadapter.jar;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
Slf4j-api still gets installed as a bundle. Does anyone know how to embed slf4j-api in a bundle to prevent it from using the exported org.slf4j.impl provided by logback?
Thanks for your help,
Brian
p.s. The full pom element is:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.3</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
<Bundle-Version>${pom.version}</Bundle-Version>
<Export-Package></Export-Package>
<Private-Package>${bundle.namespace}.internal.*</Private-Package>
<Embed-Dependency>slf4j.api_1.7.2.jar;logbackadapter.jar;scope=compile|runtime;inline=true</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuraiton>
</plugin>
And the dependency element is:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
<scope>compile</scope>
</dependency>
I suggest using Pax-Logging, this provides you all you need for logging. Only “drawback”, depending on how you look at it, it’s configured by std. log4j property file, since it uses the ConfigurationAdmin Service for this. Besides that it helps you a lot with all kinds of different loggin frameworks, log4j, slf4j, jul etc…
Pax-Logging