0
votes

I am using Apache ServiceMix 7.0.1 with Felix SCR. On startup, a number of my OSGI components are in Disabled / Unsatisfied state. In order to get some additional logs around the lifecycle of the components, I looked at changing the log levels for scr and found this article - http://felix.apache.org/documentation/subprojects/apache-felix-service-component-runtime.html But I am not clear on where to set the ds.loglevel property in ServiceMix. I tried setting the same in config.properties and also by passing as a launch argument via -D option but it did not result in any additional logging.

Can you please advise me on how to troubleshoot the failing components? Thanks.

1

1 Answers

1
votes

As far as I know scr is using the OSGi log service. In many log configurations these logs are not forwarded to the log backend.

I recently found that felix now offers a new logging solution based on logback that also works for log service as well as several types of OSGi events. So I propose you try with felix logback support bundle.

Here is a blog how to set it up: http://liquid-reality.de/2018/08/07/logging-osgi.html

Edit: The blog text is below, slightly worse formatted, from a time when the link appeared to be dead because it had moved from blog.liquid-reality.de.

Logging in OSGi seemed to be an arcane thing for quite some time. On the logback website there is still this explanation by Ekke which was surely good 2008 but in 2018 people do not accept creating their own logging bridges, adding config using fragments and tweaking start levels.

Luckily this all improved quite a lot. Apache Karaf uses pax-logging and there is now also the felix logback support bundle. In this article I will focus on the latter as it is simple to setup and has some nice features.

Example code

I added the felix logback support to my OSGi DS hello world example because logging is a core aspect in any professional development.

See the Readme in the example for instruction how to build and run it.

Logging frontends

Logback + Felix logback supports a wide range of logging frontends (slf4j, jul, log4j, logback, commons logging, OSGi Log service). For your own code I recommend to use the slf4j API. It is very slim in dependencies and provides a lot of features.

At compile time you only need the slf4j API.

<dependency>
   <groupId>org.slf4j</groupId>  
   <artifactId>slf4j-api</artifactId>
   <version>1.7.25</version>
</dependency> 

You instantiate slf4j exactly like outside OSGi. So it can also be used for hybrid code that can run inside and outside of OSGi.

class MyClass {
    Logger log = LoggerFactory.getLogger(this.getClass()); } 

Deployment

At runtime you install the bundles below. These also include the Felix log service which is used by some OSGi reference implementations.

<dependency>   <groupId>org.slf4j</groupId>  
<artifactId>slf4j-api</artifactId>   <version>1.7.25</version>
</dependency> <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.2.0</version> </dependency> <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>1.2.0</version> </dependency> <dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>org.apache.felix.log</artifactId>
    <version>1.2.0</version> </dependency> <dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>org.apache.felix.logback</artifactId>
    <version>1.0.0</version> </dependency>

The simplest way to install these is to use the bndtools bndrun packaging like in the example above.

Configuration

The logback configuration can be provided by a framework property. Logback will automatically watch the file for changes and apply new settings.

-runproperties: logback.configurationFile=file:${.}/logback.xml 

You can use plain logback configs but felix logback also provides some special settings to configure OSGi specific logs like bundle events. See the examples in the felix logback docs.

An example config can be found here.