4

In OSGi there is a separation between the logging frontend and the actual output.

So, by using the LogService, this doesnt mean that anything is written to the console for example. This is what a LogReaderService is responsible for.

In my current runtime, I am addind org.apache.felix.log which brings a LogReaderService-Implementation which should take care of the output. But I still dont see anything on the console...despite a lot of other stuff from other bundles.

In the next step I created my own LogListener which should be called by a LogServiceReader. I just used the code from this article and debugged the Activator to see if the listener is added. Still no output.

Last I checked the Felix Properties and set felix.log.level=3 (Info) but again, no output. What I was wondering even more that I still could see a lot of DEBUG-Information despite setting the level to Info?

16:47:46.311 [qtp1593165620-27] DEBUG org.eclipse.jetty.http.HttpParser

It seems to me that there are different logging strategies in place, which use different configuration properties. For example, after I added the pax-logging-service (which uses a classic logging approach) to my runtime I could see the output, but currently I would like to stick with felix-logging.

Can someone please explain how to disable Blueprint-Debug-Level, which I guess is causing the current output, and enable simple felix-logging via LogService? There must be a standard-console-implementation even though its not specified in the spec.

lostiniceland
  • 3,729
  • 6
  • 38
  • 50
  • Not too many people use the LogService. If you just need ordinary logging take a look at pax-logging. https://ops4j1.jira.com/wiki/display/paxlogging/How+to+use+Pax+Logging+in+my+bundles It allows to simply use one of the supported log frameworks in your code and configure all logging using log4j config style. – Christian Schneider Mar 05 '15 at 16:30
  • 1
    I wonder why. With classic logging I need to provide some form of config-files to each module where logging is used, whereas with LogService I can write to whatever storage I need (e.g. database) without affecting the clients. – lostiniceland Mar 05 '15 at 16:44
  • 1
    We use felix logging with a simple bundle that implements a LogListener and forwards every LogEntry to SLF4J (that logs everything to the console than). You can use that or implement an own one within an hour (e.g.: that forwards directly to Console instead or has configuration options). Our class is at https://github.com/everit-org/osgi-loglistener-slf4j/blob/master/core/src/main/java/org/everit/osgi/loglistener/slf4j/internal/Slf4jLogListener.java and you can download the bundle from Maven Central. – Balazs Zsoldos Mar 05 '15 at 19:27
  • 1
    If you use plain log4j or one of the other non OSGi frameworks it is a major pain. With pax logging you can use all the logging APIs and it works great. In most apache projects like karaf and camel we the slf4j API together with pax logging. – Christian Schneider Mar 05 '15 at 19:31

1 Answers1

1

Thanks to Christian Schneider and Balazs Zsoldos: both comments were very helpfull.

To answer the question: I need to provide a ServiceTrackerCustomizer as shown in Balazs example here. Since I already had a ConsoleLogListener it was enough to register the listener with the TrackerCustomizer.


Since my current task is about migrating a big legacy application where I would like to introduce OSGi it makes probably more sense to go with Pax-Logging since log4j is already used in hundreds of classes which we probably wont change to LogService.

The output of Pax-Logging can be adjusted with the property org.ops4j.pax.logging.DefaultServiceLog.level set to INFO

lostiniceland
  • 3,729
  • 6
  • 38
  • 50