Monday, October 20, 2008

Logging in OSGI Enterprise Applications, Part 4

Part 4 will demonstrate how to start the logging - framework and all the bridges inside an OSGI Enterprise Application.

To remember: At the end of the last (third) part of my blog - series "Logging in OSGI Enterprise Applications" we were able to log all events from „classic“ log-frameworks, OSGI LogServices, BundleEvents and FrameworkEvents using a SLF4J Log - implementation (LOGBack):

If we want to use it all inside a complex OSGI Enterprise Application its important to start the bundles using the right start-level. We also have to decide which bundles can be auto-started from the framework and which not. 

As an example I'll use again my OSGI - Equinox - Riena - EasyBeans - Hibernate - Server. I'll talk in detail about this server later in one of the follow-ups.

From OSGI Launch Configuration:

Default Start - Level is set to 3. 
Our osgi-over-slf4j - Bundle must be started before (Start-Level = 2) and the EasyBeans - Agent - Bundle later (Start-Level = 4)

We also have to watch that some bundles cannot be started with Auto-Start = true ! These bundles will be started under control from EasyBeans Agent bundle.

What happens now starting the OSGI server application ?

  1. The OSGI - Framework Equinox will be started
  2. Our org.ekkehard.osgi.over.slf4j bundle will be started. The Activator calls in the start() method SLF4JBridgeHandler.install() to catch all log - events from java.util.logging - also the Activator contains Logger - Statements. All this causes starting and activating SLF4J - API and SLF4J - implementation (LOGBack) - bundles: our Logging Framework is alive !
  3. All bundles with Auto-Start = true will be started then from the Framework. This includes all Eclipse Riena bundles. Riena uses LOG4J - so the LOG4J - bridge will be started. Riena also uses Equinox - Extended - OSGI - Log - Services.
  4. After starting all Default - Start - Level - bundles, the easybeans.agent will be started. This agent starts all EasyBeans components and Hibernate. EasyBeans uses Commons - Logging and java.util.logging - Hibernate uses SLF4J. Then all our logging -  framework - bridges are started and active. EasyBeans then starts all Entity - bundles and EJB3 - bundles from our server and registers the EJB3 - Business - Interfaces (Local oder Remote) als OSGI - Services.
  5. The org.ekkehard.server bundle tracks OSGI Managed Services and recognizes, when all required services are configured from EasyBeans and Hibernate and ready-to-go. Then org.ekkehard.server registers Services as Remote Services for Eclipse Riena.

Remark: This is only a small part of all the activities and tasks happening while starting the server. More about 4. and 5. later in another blog series. Lets first finishing the logging.

No black holes ?

If we did it all well, then our SLF4J - Implementation LOGBack should start so early that we get all log - events and nothing is lost in space. 

To test this we configure our logback-test.xml as follows: set Root Level to DEBUG, output to Console, swich DEBUG - Mode of the configuration itself on and start the server.

You should get a log like this:

  • Line 1: equinox - osgi - Console
  • Line 2 - 7: Debug-output from LOGBack configuration
  • Line 8 - 9: Logging-output from osgi-over-slf4j - bundle

There's no other logging-output on the console before starting SLF4J / LOGBack :-)

The next blog will look at the configuration of LOGBack and some special Fragment - Bundles for configuration and also extending the LOGBack - implementation.

Perhaps some of my older blogs about Logging und OSGI are also interesting:

 the blog in german.


Unknown said...

Hi there;

... and, first off, thanks a bunch for taking the time to put down this pretty impressive outline, really helped me a lot getting started with logging inside Eclipse/OSGi.

One question, however: I mostly followed your explanations step-by-step and so far things work rather smoothly, except for the logback[-test].xml in the corresponding fragment obviously being ignored. Using logback-OSGi bundles as provided by which seems to be OSGi-bundles by default in recent releases. Fragment seems included in the running platform... Any idea where to look?
TIA and all the best,

ekke said...

I'va moved my blog to - please aks there future questions. thx
If your Fragment has the right Host it should work.
But soon I'll publish how it all works using the newest versions

Unknown said...

Part 2 cannot be opened :
Anyway, great series of articles!


ekke said...

I have moved my blog to
there all should be available