Author: erodriguez Date: Sat May 13 16:53:58 2006 New Revision: 406169 URL: http://svn.apache.org/viewcvs?rev=406169&view=rev Log: 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. Added: directory/trunks/apacheds/osgi/logger/src/main/java/ directory/trunks/apacheds/osgi/logger/src/main/java/org/ directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/ directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/ directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/server/ directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/server/logger/ directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/server/logger/Activator.java (with props) Removed: directory/trunks/apacheds/osgi/logger/src/main/resources/ Modified: directory/trunks/apacheds/osgi/logger/pom.xml Modified: directory/trunks/apacheds/osgi/logger/pom.xml URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/osgi/logger/pom.xml?rev=406169&r1=406168&r2=406169&view=diff ============================================================================== --- directory/trunks/apacheds/osgi/logger/pom.xml (original) +++ directory/trunks/apacheds/osgi/logger/pom.xml Sat May 13 16:53:58 2006 @@ -6,7 +6,7 @@ build 1.1.0-SNAPSHOT - apacheds-osgi-logger + apacheds-server-logger-osgi ApacheDS Logging Library Bundle The logging library packaged as an OSGi bundle. @@ -18,6 +18,24 @@ nlog4j 1.2.19 + + org.apache.felix + org.osgi.core + 0.8.0-SNAPSHOT + provided + + + org.apache.directory.shared + shared-ldap + 0.9.6-SNAPSHOT + provided + + + org.apache.directory.shared + shared-asn1 + 0.9.6-SNAPSHOT + provided + @@ -34,6 +52,12 @@ A bundle that registers the logging library. + + org.apache.directory.server.logger.Activator + + + org.osgi.framework + org.slf4j,org.apache.log4j Added: directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/server/logger/Activator.java URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/server/logger/Activator.java?rev=406169&view=auto ============================================================================== --- directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/server/logger/Activator.java (added) +++ directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/server/logger/Activator.java Sat May 13 16:53:58 2006 @@ -0,0 +1,89 @@ +/* + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.directory.server.logger; + +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; + + 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 the file and restart the " + + bundleContext.getBundle().getLocation() + " bundle." ); + } + } +} Propchange: directory/trunks/apacheds/osgi/logger/src/main/java/org/apache/directory/server/logger/Activator.java ------------------------------------------------------------------------------ svn:eol-style = native