0

This is a follow-up (somehow of my Third-party dependencies to an OSGi application) where it was suggested that some libraries e.g. log4j are already available as bundles.
In Eclipse Indigo I could not find a log4j bundle available to Import Package as part of my installation and so I created a Plugin Project from JAR archive to bundle log4j and also a Feature Project to bundle the log4j.xml configuration following this post.

To be honest I don't understand why the fragment project is needed but this process works.
So my question now is:
Since the log4j.xml is delivered in the export as part of the feature jar, it requires some "effort" for someone to find it and update the debug levels, so I was wondering is this indeed the correct process?
I had in mind that the final exported product would deliver the log4j configuration in an easy to find location, but now (although the logging works) I am concerned whether what I do, is indeed correct.

Any help here?

3 Answers 3

2

If you really need to expose the file, you could put it anywhere you want, and then make sure your program calls one of these methods at startup:

  • org.apache.log4j.xml.DOMConfigurator.configure(String filename)
  • org.apache.log4j.PropertyConfigurator.configure(String configFilename)

Or use the "configureAndWatch"-variants if you would like to make changes to the config without restarting your application.

Edit: I write "If you really need to", because I have experienced that I never need to turn on debug-logging after deployment, because it is always turned on! This is OK for applications where I have normal (but not extreme) requirements on response-time and throughput. Logging to an UDP-appender is fast (and does not fill up the disk). Or using rolling file appender is quite safe, and fast enough for my use. Always having the debug-log available is a life-saver when nailing down those hard-to-reproduce bugs.

4
  • I will try this but why are you saying "if you really need to.."?The idea in log4j is that the end user could turn-on/off debugging when needed.Not sure what is your point.
    – Cratylus
    Oct 20, 2012 at 8:17
  • I have updated my answer with a clarification, thanks for pointing it out, Cratylus. :-)
    – Eirik W
    Nov 20, 2012 at 14:26
  • Debug-on always?That depends on the application and how much logging is being done
    – Cratylus
    Nov 20, 2012 at 17:40
  • Yes, it depends on your exact case and how much logging is being done. My point is only that I have been suprised to experience how much logging we could have enabeled, and still not have a noticably negative effect on performance, for our application(s). So it is worth trying for those who have not tried it before because they were assuming (but not knowing) that their applications would be slow.
    – Eirik W
    Nov 22, 2012 at 14:02
1

I suggest take a look at Pax-Logging this will give you all kinds of logging frameworks for usage in a OSGi environment. And you're able to use an external configuration file (no extender needed) to configure your logging.

1

The fragment is one option to extend the log4j bundles classpath to include the required configuration file. It is probably the simplest way of configuring application wide properties.

This is not meant to be altered after deployment though as it will be embedded within a jar file. You will have to come up with a different approach if you expect to make it configurable after deployment.

NOTE: I am afraid you misunderstood the answer about the jars that are already available as bundles. This does not mean that they are part of your OSGi platform of choice (Indigo), only that they are ready to be deployed to an OSGi platform as is. Your creation of a plugin project was unnecessary, you simply needed to add the jar to your target platform to resolve your missing imports.

1
  • 1)But using log4j isn't it natural to expect that the log4j.xml would be updated after deployment?What different approach is there?What is usually done for logging?2)I read that it is a bad practice to use the target platform since I may have problems in deployments.Am I wrong?
    – Cratylus
    Oct 1, 2012 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.