aVineas.org aVineas open source Java code

Introduction

Log4j is a logging back-end used in various applications. The configuration of logging is done via a property or XML file that is loaded from the class path. The problem with this in an OSGi environment is that it is not possible to dynamically change the logging configuration, for example to add debug logging at a specific time. The bundle provided here doesn't have this restriction: when the bundle is restarted, the logging configuration is re-read.

Usage

The log4j bundle consists of a bundle activator that determines the location of the log4j configuration at the following locations:

  1. It looks at the property "file" of the "log4.configuration" PID as provided by a configuration admin service (see OSGi compendium chapter 104).
  2. If no property "file" is provided by a configuration manager, it defaults to the relative path "configuration/log4j.xml".
  3. If the file cannot be found, it defaults to the log4j.xml file provided with the bundle. That logging configuration logs everything at informational level or above to the console.

As stated: restarting the bundle will cause the logging configuration to be re-loaded.

Therefore, to use this bundle either put a logging configuration in the file "configuration/log4j.xml" or specify a different value for the "file" property in the "log4j.configuration" PID at a configuration admin service. Note that "file" may point to a properties file in stead a XML file. In that case, the file should have the .properties extension.

The bundle exports all packages exported by the log4j jar.

Dependencies

The bundle has no other dependencies apart from the standard OSGi and OSGi compendium interfaces. The log4j jar version 1.2.15 is included in the bundle.

Download

org.avineas.log4j_1.0.2.jar

Copyright 2010-2024, aVineas IT Consulting