Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: [LOGGING-149] - Add documentation on how to use commons logging in OSGi environments

...

When providing an implementation of the org.apache.commons.logging.Log interface, the implementation must define a constructor that takes a java.lang.String as an argument. Otherwise you get an "org.apache.commons.logging.LogConfigurationException: User-specified log class '...' cannot be found or is not useable."

How can I use commons-logging in an OSGi environment?

Commons-logging was not designed with OSGi in mind. This is why it is difficult to get commons-logging working in OSGi environments:

  • LogFactory loads Log implementations by name (see Class.forName(String)). This is usually not possible in OSGi since every bundle classloader can only see the classes a bundle defines imports for.
  • The bundle class loader that loads the commons-logging bundle will not have access to user provided commons-logging.properties files.
  • commons-logging-api.jar contains classes that are also included in commons-logging.jar. This is contrary to traditional OSGi application architectures where one bundle defines an API and other bundles provide implementations for that API.

There alternatives to using commons-logging directly in OSGi are:

Further information about this topic is available in the archives of the commons dev ML and the felix dev ML and in Jira.

...

Up to Logging