[slf4j-dev] svn commit: r718 - in slf4j/trunk/osgi-over-slf4j: . src src/main src/main/java src/main/java/org src/main/java/org/slf4j src/main/java/org/slf4j/osgi src/main/java/org/slf4j/osgi/logservice src/main/java/org/slf4j/osgi/logservice/impl
jconlon at slf4j.org
jconlon at slf4j.org
Wed Feb 7 22:26:50 CET 2007
Author: jconlon
Date: Wed Feb 7 22:26:50 2007
New Revision: 718
Added:
slf4j/trunk/osgi-over-slf4j/
slf4j/trunk/osgi-over-slf4j/pom.xml
slf4j/trunk/osgi-over-slf4j/src/
slf4j/trunk/osgi-over-slf4j/src/main/
slf4j/trunk/osgi-over-slf4j/src/main/java/
slf4j/trunk/osgi-over-slf4j/src/main/java/org/
slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/
slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/
slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/logservice/
slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/logservice/impl/
slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/logservice/impl/Activator.java
slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/logservice/impl/LogServiceFactory.java
slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/logservice/impl/LogServiceImpl.java
Log:
A slf4j OSGi LogService implementation.
Added: slf4j/trunk/osgi-over-slf4j/pom.xml
==============================================================================
--- (empty file)
+++ slf4j/trunk/osgi-over-slf4j/pom.xml Wed Feb 7 22:26:50 2007
@@ -0,0 +1,64 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-parent</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.slf4j</groupId>
+ <artifactId>osgi-over-slf4j</artifactId>
+ <version>${parent.version}</version>
+ <packaging>bundle</packaging>
+ <name>OSGi LogService Implemented Over SLF4J</name>
+
+ <url>http://www.slf4j.org</url>
+ <description>
+ OSGi LogService implementation over SLF4J
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>4.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>0.9.0-incubator-SNAPSHOT</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.osgi.service.log
+ </Export-Package>
+ <Import-Package>org.slf4j;version="[1.3,1.4)",*</Import-Package>
+ <Private-Package>org.slf4j.osgi.logservice.impl</Private-Package>
+ <Bundle-Activator>org.slf4j.osgi.logservice.impl.Activator</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added: slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/logservice/impl/Activator.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/logservice/impl/Activator.java Wed Feb 7 22:26:50 2007
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2004-2005 QOS.ch
+ *
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
+ * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ *
+ */
+
+package org.slf4j.osgi.logservice.impl;
+
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.service.log.LogService;
+
+/**
+ * <code>Activator</code> implements a simple bundle that registers a
+ * {@link LogServiceFactory} for the creation of {@link LogService} implementations.
+**/
+public class Activator implements BundleActivator {
+
+ /**
+ *
+ * Implements <code>BundleActivator.start()</code> to register a
+ * LogServiceFactory.
+ *
+ * @param bundleContext the framework context for the bundle
+ * @throws Exception
+ */
+ public void start(BundleContext bundleContext) throws Exception {
+ Hashtable props = new Hashtable();
+ props.put("description", "An slf4j implementation.");
+ ServiceFactory factory = new LogServiceFactory();
+ bundleContext.registerService(LogService.class.getName(), factory, props);
+ }
+
+ /**
+ *
+ * Implements <code>BundleActivator.stop()</code>.
+ *
+ * @param bundleContext the framework context for the bundle
+ * @throws Exception
+ */
+ public void stop(BundleContext bundleContext) throws Exception {
+
+ // Note: It is not required that we remove the service here, since
+ // the framework will do it automatically anyway.
+ }
+
+
+}
Added: slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/logservice/impl/LogServiceFactory.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/logservice/impl/LogServiceFactory.java Wed Feb 7 22:26:50 2007
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2004-2005 QOS.ch
+ *
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
+ * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ *
+ */
+
+package org.slf4j.osgi.logservice.impl;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * <code>LogServiceFactory</code> creates LogService implemenations.
+ *
+ * @author John Conlon
+ * @version $Rev$, $Date$
+ */
+public class LogServiceFactory implements ServiceFactory
+{
+
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
+ */
+ public Object getService( Bundle bundle, ServiceRegistration arg1 )
+ {
+
+ return new LogServiceImpl(bundle);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
+ */
+ public void ungetService( Bundle bundle, ServiceRegistration arg1, Object arg2 )
+ {
+ // Ignore for now
+
+ }
+
+}
Added: slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/logservice/impl/LogServiceImpl.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/osgi-over-slf4j/src/main/java/org/slf4j/osgi/logservice/impl/LogServiceImpl.java Wed Feb 7 22:26:50 2007
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2004-2005 QOS.ch
+ *
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
+ * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ *
+ */
+
+package org.slf4j.osgi.logservice.impl;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <code>LogServiceImpl</code> is a simple OSGi LogService implemenation that delegates to a slf4j
+ * Logger.
+ *
+ * @author John Conlon
+ */
+public class LogServiceImpl implements LogService {
+
+ private static final String UNKNOWN = "[Unknown]";
+
+ private final Logger delegate;
+
+ /**
+ * Creates a new instance of LogServiceImpl.
+ *
+ */
+ public LogServiceImpl(Bundle bundle) {
+ String name = (String) bundle.getHeaders().get(
+ Constants.BUNDLE_SYMBOLICNAME);
+ String version = (String) bundle.getHeaders().get(
+ Constants.BUNDLE_VERSION);
+ delegate = LoggerFactory.getLogger(name + '.' + version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.service.log.LogService#log(int, java.lang.String)
+ */
+ 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;
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.service.log.LogService#log(int, java.lang.String,
+ * java.lang.Throwable)
+ */
+ 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;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.service.log.LogService#log(org.osgi.framework.ServiceReference,
+ * int, java.lang.String)
+ */
+ public void log(ServiceReference sr, int level, String message) {
+ String output = createMessage(sr, message);
+
+ switch (level) {
+ case LOG_DEBUG:
+ delegate.debug(output);
+ break;
+ case LOG_ERROR:
+ delegate.error(output);
+ break;
+ case LOG_INFO:
+ delegate.info(output);
+ break;
+ case LOG_WARNING:
+ delegate.warn(output);
+ break;
+ default:
+ break;
+ }
+ }
+
+ /**
+ * createMessage.
+ *
+ * @param sr
+ * @param message
+ * @return
+ */
+ private String createMessage(ServiceReference sr, String message) {
+ StringBuffer output = new StringBuffer();
+ if (sr != null) {
+ output.append('[').append(sr.toString()).append(']')
+ .append(message);
+ } else {
+ output.append(UNKNOWN).append(message);
+ }
+ return output.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.service.log.LogService#log(org.osgi.framework.ServiceReference,
+ * int, java.lang.String, java.lang.Throwable)
+ */
+ public void log(ServiceReference sr, int level, String message,
+ Throwable exception) {
+ String output = createMessage(sr, message);
+
+ switch (level) {
+ case LOG_DEBUG:
+ delegate.debug(output, exception);
+ break;
+ case LOG_ERROR:
+ delegate.error(output, exception);
+ break;
+ case LOG_INFO:
+ delegate.info(output, exception);
+ break;
+ case LOG_WARNING:
+ delegate.warn(output, exception);
+ break;
+ default:
+ break;
+ }
+ }
+
+}
More information about the slf4j-dev
mailing list