You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2006/05/14 01:54:00 UTC
svn commit: r406169 - in /directory/trunks/apacheds/osgi/logger: ./
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/directory/
src/main/java/org/apache/directory/server/
src/main/java/org/apache/directory/server/log...
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 @@
<artifactId>build</artifactId>
<version>1.1.0-SNAPSHOT</version>
</parent>
- <artifactId>apacheds-osgi-logger</artifactId>
+ <artifactId>apacheds-server-logger-osgi</artifactId>
<name>ApacheDS Logging Library Bundle</name>
<description>
The logging library packaged as an OSGi bundle.
@@ -18,6 +18,24 @@
<artifactId>nlog4j</artifactId>
<version>1.2.19</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.shared</groupId>
+ <artifactId>shared-ldap</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.shared</groupId>
+ <artifactId>shared-asn1</artifactId>
+ <version>0.9.6-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
@@ -34,6 +52,12 @@
<bundleDescription>
A bundle that registers the logging library.
</bundleDescription>
+ <bundleActivator>
+ org.apache.directory.server.logger.Activator
+ </bundleActivator>
+ <importPackage>
+ org.osgi.framework
+ </importPackage>
<exportPackage>
org.slf4j,org.apache.log4j
</exportPackage>
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