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 ?
- The OSGI – Framework Equinox will be started
- 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 !
- 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.
- 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.
- 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.
- Part 1: An overview
- Part 2: How to catch all log events from “classic” logging – frameworks
- Part 3: How to catch all log events from OSGI Log Services
- Part 4: How to start logging bundles the right way inside an OSGI Enterprise application
- Part 5: … follows (Stay tuned…)
Perhaps some of my older blogs about Logging und OSGI are also interesting:
the blog in german.