You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by jc...@apache.org on 2006/11/18 17:23:53 UTC
svn commit: r476558 - in
/directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging:
Activator.java LogServiceImpl.java
Author: jconlon
Date: Sat Nov 18 08:23:53 2006
New Revision: 476558
URL: http://svn.apache.org/viewvc?view=rev&rev=476558
Log:
Reformated with ApacheDS code style
Modified:
directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/Activator.java
directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/LogServiceImpl.java
Modified: directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/Activator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/Activator.java?view=diff&rev=476558&r1=476557&r2=476558
==============================================================================
--- directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/Activator.java (original)
+++ directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/Activator.java Sat Nov 18 08:23:53 2006
@@ -18,27 +18,26 @@
import org.slf4j.LoggerFactory;
/**
- * BundleActivator for logging services.
+ * BundleActivator for logging services.
*
- * A log4j configuration can be specified to this bundle
- * in a number of ways:
+ * A log4j configuration can be specified to this bundle in a number of ways:
* <ul>
- * <li>A log4j.properties file can be located in a conf subdirectory
- * of the working directory
- * <li>The log4j.configuration bundle property can be set to the url of
- * the configuration file
+ * <li>A log4j.properties file can be located in a conf subdirectory of the
+ * working directory
+ * <li>The log4j.configuration bundle property can be set to the url of the
+ * configuration file
* <li>If neither 1 or 2 above then a default basic configuration will be used
* </ul>
* <p>
- * To observe the inner workings of log4j configuration set the log4j.debug system
- * property to true.
+ * To observe the inner workings of log4j configuration set the log4j.debug
+ * system property to true.
*
*/
-public class Activator implements BundleActivator {
+public class Activator implements BundleActivator
+{
- private static final String DEFALT_LOG_CONF_PATH = System
- .getProperty("user.dir")
- + File.separator + "conf" + File.separator + "log4j.properties";
+ private static final String DEFALT_LOG_CONF_PATH = System.getProperty( "user.dir" ) + File.separator
+ + "conf" + File.separator + "log4j.properties";
private static final String VENDOR = "org.apache";
@@ -46,7 +45,8 @@
private Logger log = null;
- public Activator() {
+ public Activator()
+ {
super();
}
@@ -54,29 +54,36 @@
* On bundle start reload the log4J configuration and register the
* logService.
*/
- public void start(BundleContext bundleContext) throws Exception {
- try {
- resetLog4j(bundleContext);
-
- } catch (MalformedURLException e) {
- System.err.println(Activator.class.getName()+": MalformedURLException - Failed to find the log configuration file at path: "
- + e.getLocalizedMessage());
- } catch (Exception e) {
- System.err.println(Activator.class.getName()+": Exception - Failed to find the log configuration file at path: "
- + e.getLocalizedMessage());
+ public void start( BundleContext bundleContext ) throws Exception
+ {
+ try
+ {
+ resetLog4j( bundleContext );
+
+ } catch (MalformedURLException e)
+ {
+ System.err.println( Activator.class.getName()
+ + ": MalformedURLException - Failed to find the log configuration file at path: "
+ + e.getLocalizedMessage() );
+ } catch (Exception e)
+ {
+ System.err.println( Activator.class.getName()
+ + ": Exception - Failed to find the log configuration file at path: "
+ + e.getLocalizedMessage() );
e.printStackTrace();
}
- registerLogService(bundleContext);
+ registerLogService( bundleContext );
}
- private void registerLogService(BundleContext bundleContext) {
+ private void registerLogService( BundleContext bundleContext )
+ {
Dictionary<String, String> parameters = new Hashtable<String, String>();
- parameters.put(Constants.SERVICE_VENDOR, VENDOR);
- bundleContext.registerService(LogService.class.getName(),
- new LogServiceImpl(), parameters);
+ parameters.put( Constants.SERVICE_VENDOR, VENDOR );
+ bundleContext.registerService( LogService.class.getName(), new LogServiceImpl(), parameters );
}
- public void stop(BundleContext arg0) throws Exception {
+ public void stop( BundleContext arg0 ) throws Exception
+ {
}
/**
@@ -85,19 +92,23 @@
* @throws MalformedURLException
*
*/
- private URL getLoggingProperty(BundleContext bundleContext)
- throws FileNotFoundException, MalformedURLException {
- String logPropertiesLocation = bundleContext
- .getProperty(LOG_PROPERTIES_LOCATION);
- if (logPropertiesLocation == null) {
- File defaultConf = new File(DEFALT_LOG_CONF_PATH);
- if (defaultConf.exists()) {
+ private URL getLoggingProperty( BundleContext bundleContext ) throws FileNotFoundException,
+ MalformedURLException
+ {
+ String logPropertiesLocation = bundleContext.getProperty( LOG_PROPERTIES_LOCATION );
+ if ( logPropertiesLocation == null )
+ {
+ File defaultConf = new File( DEFALT_LOG_CONF_PATH );
+ if ( defaultConf.exists() )
+ {
logPropertiesLocation = defaultConf.toURI().toString();
- } else {
+ }
+ else
+ {
return null;
}
}
- return new URL(logPropertiesLocation);
+ return new URL( logPropertiesLocation );
}
/**
@@ -107,22 +118,29 @@
* @throws MalformedURLException
* @throws FileNotFoundException
*/
- private void resetLog4j(BundleContext bundleContext)
- throws MalformedURLException, FileNotFoundException {
+ private void resetLog4j( BundleContext bundleContext ) throws MalformedURLException,
+ FileNotFoundException
+ {
LogManager.resetConfiguration();
- URL log4jprops = getLoggingProperty(bundleContext);
+ URL log4jprops = getLoggingProperty( bundleContext );
- if (log4jprops != null) {
- System.out.println(Activator.class.getName()+": Setting log4j configuration to: "+log4jprops);
- PropertyConfigurator.configure(log4jprops);
- log = LoggerFactory.getLogger(Activator.class);
- log.info("Reset log configuration, with configuration: "
- + log4jprops);
- } else {
+ if ( log4jprops != null )
+ {
+ System.out
+ .println( Activator.class.getName() + ": Setting log4j configuration to: " + log4jprops );
+ PropertyConfigurator.configure( log4jprops );
+ log = LoggerFactory.getLogger( Activator.class );
+ log.info( "Reset log configuration, with configuration: " + log4jprops );
+ }
+ else
+ {
BasicConfigurator.configure();
- log = LoggerFactory.getLogger(Activator.class);
- log.warn("A basic logging configuration was created because the logging configuration property: "+LOG_PROPERTIES_LOCATION+
- " was not set and the default log configuration "+DEFALT_LOG_CONF_PATH+" was empty. ");
+ log = LoggerFactory.getLogger( Activator.class );
+ log
+ .warn( "A basic logging configuration was created because the logging configuration property: "
+ + LOG_PROPERTIES_LOCATION
+ + " was not set and the default log configuration "
+ + DEFALT_LOG_CONF_PATH + " was empty. " );
}
}
Modified: directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/LogServiceImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/LogServiceImpl.java?view=diff&rev=476558&r1=476557&r2=476558
==============================================================================
--- directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/LogServiceImpl.java (original)
+++ directory/sandbox/jconlon/osgi-services/logging-service/src/main/java/org/apache/directory/osgi/services/logging/LogServiceImpl.java Sat Nov 18 08:23:53 2006
@@ -1,18 +1,15 @@
package org.apache.directory.osgi.services.logging;
-
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.osgi.service.log.LogService;
-
public class LogServiceImpl implements LogService
{
/** the log for this class */
private static final Logger delegate = LoggerFactory.getLogger( LogServiceImpl.class );
-
/**
* Logs a message.
*
@@ -35,26 +32,24 @@
*/
public void log( int level, String message )
{
- switch ( level )
- {
- case LOG_DEBUG:
- delegate.debug( message );
- break;
- case LOG_ERROR:
- delegate.error( message );
- break;
- case LOG_INFO:
- delegate.info( message );
- break;
- case LOG_WARNING:
- delegate.warn( message );
- break;
- default:
- break;
+ switch (level) {
+ case LOG_DEBUG:
+ delegate.debug( message );
+ break;
+ case LOG_ERROR:
+ delegate.error( message );
+ break;
+ case LOG_INFO:
+ delegate.info( message );
+ break;
+ case LOG_WARNING:
+ delegate.warn( message );
+ break;
+ default:
+ break;
}
}
-
/**
* Logs a message with an exception.
*
@@ -78,26 +73,24 @@
*/
public void log( int level, String message, Throwable exception )
{
- switch ( level )
- {
- case LOG_DEBUG:
- delegate.debug( message, exception );
- break;
- case LOG_ERROR:
- delegate.error( message, exception );
- break;
- case LOG_INFO:
- delegate.info( message, exception );
- break;
- case LOG_WARNING:
- delegate.warn( message, exception );
- break;
- default:
- break;
+ switch (level) {
+ case LOG_DEBUG:
+ delegate.debug( message, exception );
+ break;
+ case LOG_ERROR:
+ delegate.error( message, exception );
+ break;
+ case LOG_INFO:
+ delegate.info( message, exception );
+ break;
+ case LOG_WARNING:
+ delegate.warn( message, exception );
+ break;
+ default:
+ break;
}
}
-
/**
* Logs a message associated with a specific <code>ServiceReference</code>
* object.
@@ -123,26 +116,24 @@
*/
public void log( ServiceReference sr, int level, String message )
{
- switch ( level )
- {
- case LOG_DEBUG:
- delegate.debug( '[' + sr.getBundle().getBundleId() + ']' + message );
- break;
- case LOG_ERROR:
- delegate.error( '[' + sr.getBundle().getBundleId() + ']' + message );
- break;
- case LOG_INFO:
- delegate.info( '[' + sr.getBundle().getBundleId() + ']' + message );
- break;
- case LOG_WARNING:
- delegate.warn( '[' + sr.getBundle().getBundleId() + ']' + message );
- break;
- default:
- break;
+ switch (level) {
+ case LOG_DEBUG:
+ delegate.debug( '[' + sr.getBundle().getBundleId() + ']' + message );
+ break;
+ case LOG_ERROR:
+ delegate.error( '[' + sr.getBundle().getBundleId() + ']' + message );
+ break;
+ case LOG_INFO:
+ delegate.info( '[' + sr.getBundle().getBundleId() + ']' + message );
+ break;
+ case LOG_WARNING:
+ delegate.warn( '[' + sr.getBundle().getBundleId() + ']' + message );
+ break;
+ default:
+ break;
}
}
-
/**
* Logs a message with an exception associated and a
* <code>ServiceReference</code> object.
@@ -166,22 +157,21 @@
*/
public void log( ServiceReference sr, int level, String message, Throwable exception )
{
- switch ( level )
- {
- case LOG_DEBUG:
- delegate.debug( '[' + sr.getBundle().getBundleId() + ']' + message, exception );
- break;
- case LOG_ERROR:
- delegate.error( '[' + sr.getBundle().getBundleId() + ']' + message, exception );
- break;
- case LOG_INFO:
- delegate.info( '[' + sr.getBundle().getBundleId() + ']' + message, exception );
- break;
- case LOG_WARNING:
- delegate.warn( '[' + sr.getBundle().getBundleId() + ']' + message, exception );
- break;
- default:
- break;
+ switch (level) {
+ case LOG_DEBUG:
+ delegate.debug( '[' + sr.getBundle().getBundleId() + ']' + message, exception );
+ break;
+ case LOG_ERROR:
+ delegate.error( '[' + sr.getBundle().getBundleId() + ']' + message, exception );
+ break;
+ case LOG_INFO:
+ delegate.info( '[' + sr.getBundle().getBundleId() + ']' + message, exception );
+ break;
+ case LOG_WARNING:
+ delegate.warn( '[' + sr.getBundle().getBundleId() + ']' + message, exception );
+ break;
+ default:
+ break;
}
}