[osgi logging] part 4 – Extend Logback Classic Bundle

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.

Fragment Bundles

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:

logback.classic fragments

Lilith is a Logging and Access Event Viewer for the Logback Logging Framework. (something like “Chainsaw” for Log4J). A review of Lilith follows.

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:

logging bundles

Hint: to see all dependencies please take a look at the MANIFEST.MF’s from the bundles mentioned above.

Additional Dependencies

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:

com.springsource.javax.activation-1.1.1.jar
com.springsource.javax.mail-1.4.1.jar
com.springsource.org.apache.tools.ant-1.7.1.jar
com.springsource.org.apache.tools.ant.launch-1.7.1.jar
com.springsource.org.codehaus.janino-2.5.15.jar
  • com.springsource.javax.activation-1.1.1.jar
  • com.springsource.javax.mail-1.4.1.jar
  • com.springsource.org.apache.tools.ant-1.7.1.jar
  • com.springsource.org.apache.tools.ant.launch-1.7.1.jar
  • com.springsource.org.codehaus.janino-2.5.15.jar

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…

2 responses

  1. Pingback: Logging in OSGI Applications – Monitor Log Messages (Lilith) « ekkes-corner: eclipse | osgi | mdsd | erp

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,067 other followers

%d bloggers like this: