Issue Details (XML | Word | Printable)

Key: DIRSERVER-611
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Enrique Rodriguez
Reporter: John Conlon
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Directory ApacheDS

An OSGi Activator can allow simple way for reconfiguration of log4j.properties without restarting the JVM.

Created: 28/Apr/06 02:58 AM   Updated: 13/Dec/06 09:12 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.5.0

Time Tracking:
Not Specified

Resolution Date: 14/May/06 06:55 AM


 Description  « Hide
Runtime changes to the log4j.properties file require reconfiguration of the logging infrastructure.

Adding an the attached Activator to an OSGi bundle that exports LOG4J and SLF4J packages a bundle can offer LOG4J and SLF4J packages to other bundles and offer a solution for reconfiguration of the logging infrastructure without restarting the JVM.

--------------------------------------------------

import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.log4j.LogManager;
import org.apache.log4j.PropertyConfigurator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Activator implements BundleActivator
{
  private static final String LOG_PROPERTIES_LOCATION =
   "log4j.configuration";

  private Logger log = null;

  public void start(BundleContext bundleContext) throws Exception
  {
                try
                {
                        resetLog4j(bundleContext);
                }
                catch (Exception e)
                {
                        //e.printStackTrace();
                }
                log = LoggerFactory.getLogger(Activator.class);
                log.debug("Reset log configuration.");
  }

  public void stop(BundleContext arg0) throws Exception {}

  /**
   * @return url of the log4j.properties configuration file
   *
   * @throws MalformedURLException
   *
   */
  private URL getLoggingProperty(BundleContext bundleContext)
                        throws MalformedURLException
  {
                final String logPropertiesLocation = bundleContext
                                .getProperty(LOG_PROPERTIES_LOCATION);
                return new URL(logPropertiesLocation);
  }

  /**
   * Reset the log4j configuration.
   * @param bundleContext
   * @throws MalformedURLException
   * @throws FileNotFoundException
   */
  private void resetLog4j(BundleContext bundleContext)
                        throws MalformedURLException,
                              FileNotFoundException
  {
                
    LogManager.resetConfiguration();
    URL log4jprops = getLoggingProperty(bundleContext);

    if (log4jprops != null)
    {
      PropertyConfigurator.configure(log4jprops);
    }
    else
    {
      throw new FileNotFoundException(bundleContext
        .getProperty(LOG_PROPERTIES_LOCATION)
        + " could not be found. "
        + "Please specify add the file and restart the "
        + bundleContext.getBundle().getLocation() + " bundle.");
     }
  }
}

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #406169 Sat May 13 23:53:58 UTC 2006 erodriguez Improvements to basic OSGi logging bundle:
o Added Activator to allow reconfiguration of log4j.properties (DIRSERVER-611).
o Updated POM to use Activator, import OSGi core.
o Removed embedded default log4j.properties resource.
Files Changed
ADD /directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/server
ADD /directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory
DEL /directory/trunks/apacheds/osgi/logger/src/main/resources
ADD /directory/trunks/apacheds/osgi/logger/src/main/java/org/apache
ADD /directory/trunks/apacheds/osgi/logger/src/main/java
ADD /directory/trunks/apacheds/osgi/logger/src/main/java/org
ADD /directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/server/logger/Activator.java
MODIFY /directory/trunks/apacheds/osgi/logger/pom.xml
ADD /directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/server/logger

Enrique Rodriguez added a comment - 14/May/06 06:55 AM
Activator committed on revision 406169 as part of the ApacheDS OSGi build logging bundle.

Enrique Rodriguez made changes - 14/May/06 06:55 AM
Field Original Value New Value
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Assignee Enrique Rodriguez [ enriquer9 ]
Fix Version/s 1.1.0 [ 12310790 ]
John Conlon added a comment - 13/Dec/06 09:12 PM
Done.

John Conlon made changes - 13/Dec/06 09:12 PM
Status Resolved [ 5 ] Closed [ 6 ]