This is part 4 of my blogseries about ‘Logging in OSGI Enterprise Applications‘ – you’ll find all parts here.
Sometimes you’ll have to extend the standard behaviour of the Logging Framework:
- add new appenders (from 3rdParty or write your own)
- add Marker Converters
Look at the documentation of SLF4J and Logback – there are many parts where you can customize or extend the defaults.
The Logging Implementation (logback.classic bundle in this case) must know the Classes from your extensions and your extensions need to know the Classes from logback.classic. So you run into this classical OSGI dependency problem.
I’m really no friend of DynamicImport-Package: * which breaks modularity, slows things down and should be avoided if possible.
Another solution is the use of Eclipse Buddy Classloading, but this should only be used if there’s no other way to solve it.
In this case I decided to use Fragment-Bundles where logback.classic works as Host-Bundle. The bad thing with Fragment Bundles is, that you couldn’t start them dynamic and change in a running system – Fragments must be there at Startup-time. But extending your underlying Logging Implementation from my POV doesn’t need to be dynamic – it happens seldom.
In the bundles I’ll provide to download at the end of this series you’ll find two Fragment Bundles as an example:
Lilith Multiplexer Fragment adds the de.huxhorn.lilith.logback.appender.ClassicMultiplexSocketAppender to Logback. This Appender can be used as a replacement of logbacks classic SocketAppender and provides:
- sending LogEvents message-based (Logback’s default SocketAppender streams LogEvents using ObjectOutputStream)
- sending LogEvents to multiple remote hosts while only serialized once
- compressing LogEvents using GZIP
- supports heartbeat and timeout
This Fragment contains all Jar’s from Lilith which are needed to provide the ClassicMultiplexSocketAppender. After adding this Fragment to logback.classic it works like the Lilith Multiplexer Appender is a part of Logback itself.
The other Fragment (logback.util.fragment) contains only one class (BundleMarkerConverter extends ClassicConverter) converting a Marker I’ll talk later about.
Overview of used Bundles
The three bundles at the top are providing packages of Log4J and commons.logging and also a Bridge to java.util Logging:
Hint: to see all dependencies please take a look at the MANIFEST.MF’s from the bundles mentioned above.
As a minimum installation you should have installed:
- Eclipse 3.5 SDK (also tested using 3.6 M1)
- XML Editors (we need some xml packages) – you’ll found this at Galileo or Helios Releases Update Site, perhaps take a look at my collection of P2 Update Sites.
Additional needed Bundles to get the whole functionality of Logback:
All Bundles are available at S2 Enterprise Bundle Repository – but you should take a look at your own IDE configuration or Target Platform Definition – if you installed more then the SDK, then perhaps some of these packages are already there. (Search for bundles without the prefix com.springsource)
you’ll find the overview of this blog series here. stay tuned… part5 follows…