Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
liborjelinek committed Sep 21, 2012
2 parents e701a43 + 3e121c2 commit d6205bf
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 69 deletions.
30 changes: 14 additions & 16 deletions osgi-over-slf4j/pom.xml
@@ -1,37 +1,37 @@
<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.7.2-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>

<groupId>org.slf4j</groupId>
<artifactId>osgi-over-slf4j</artifactId>
<packaging>bundle</packaging>
<name>OSGi LogService Implemented Over SLF4J</name>
<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>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>4.0</version>
<artifactId>org.osgi.enterprise</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand All @@ -40,21 +40,19 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>0.9.0-incubator-SNAPSHOT</version>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>org.osgi.service.log</Export-Package>
<Import-Package>org.slf4j;version=${project.version},*</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>
</build>
</project>
@@ -1,8 +1,8 @@
/*
/*
* 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
Expand All @@ -12,7 +12,7 @@
* 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
Expand All @@ -22,7 +22,7 @@
* 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
Expand All @@ -32,46 +32,43 @@

package org.slf4j.osgi.logservice.impl;

import java.util.Hashtable;
import java.util.Properties;

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
* <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
*
* 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();
Properties props = new Properties();
props.put("description", "An slf4j implementation.");
ServiceFactory factory = new LogServiceFactory();
bundleContext.registerService(LogService.class.getName(), factory, props);
bundleContext.registerService(LogService.class.getName(), factory, props);
}

/**
*
* Implements <code>BundleActivator.stop()</code>.
*
*
* 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.
}


}
@@ -1,8 +1,8 @@
/*
/*
* 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
Expand All @@ -12,7 +12,7 @@
* 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
Expand All @@ -22,7 +22,7 @@
* 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
Expand All @@ -37,21 +37,18 @@
import org.osgi.framework.ServiceRegistration;

/**
* <code>LogServiceFactory</code> creates LogService implemenations.
* <code>LogServiceFactory</code> creates LogService implementations.
*
* @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);
}

Expand All @@ -61,8 +58,6 @@ public Object getService( Bundle bundle, ServiceRegistration arg1 )
*/
public void ungetService( Bundle bundle, ServiceRegistration arg1, Object arg2 )
{
// Ignore for now

//nothing to do.
}

}
@@ -1,8 +1,8 @@
/*
/*
* 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
Expand All @@ -12,7 +12,7 @@
* 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
Expand All @@ -22,7 +22,7 @@
* 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
Expand All @@ -40,9 +40,9 @@
import org.slf4j.LoggerFactory;

/**
* <code>LogServiceImpl</code> is a simple OSGi LogService implemenation that delegates to a slf4j
* <code>LogServiceImpl</code> is a simple OSGi LogService implementation that delegates to a slf4j
* Logger.
*
*
* @author John Conlon
*/
public class LogServiceImpl implements LogService {
Expand All @@ -53,7 +53,7 @@ public class LogServiceImpl implements LogService {

/**
* Creates a new instance of LogServiceImpl.
*
*
*/
public LogServiceImpl(Bundle bundle) {
String name = (String) bundle.getHeaders().get(
Expand All @@ -65,7 +65,7 @@ public LogServiceImpl(Bundle bundle) {

/*
* (non-Javadoc)
*
*
* @see org.osgi.service.log.LogService#log(int, java.lang.String)
*/
public void log(int level, String message) {
Expand All @@ -85,12 +85,11 @@ public void log(int level, String message) {
default:
break;
}

}

/*
* (non-Javadoc)
*
*
* @see org.osgi.service.log.LogService#log(int, java.lang.String,
* java.lang.Throwable)
*/
Expand All @@ -115,12 +114,12 @@ public void log(int level, String message, Throwable exception) {

/*
* (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) {

switch (level) {
case LOG_DEBUG:
if(delegate.isDebugEnabled()){
Expand Down Expand Up @@ -148,26 +147,27 @@ public void log(ServiceReference sr, int level, String message) {
}

/**
* createMessage.
* Formats the log message to indicate the service sending it, if known.
*
* @param sr
* @param message
* @return
* @param sr the ServiceReference sending the message.
* @param message The message to log.
* @return The formatted log message.
*/
private String createMessage(ServiceReference sr, String message) {
StringBuffer output = new StringBuffer();
StringBuilder output = new StringBuilder();
if (sr != null) {
output.append('[').append(sr.toString()).append(']')
.append(message);
output.append('[').append(sr.toString()).append(']');
} else {
output.append(UNKNOWN).append(message);
output.append(UNKNOWN);
}
output.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)
*/
Expand Down Expand Up @@ -199,5 +199,4 @@ public void log(ServiceReference sr, int level, String message,
break;
}
}

}
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -61,6 +61,7 @@
<module>jcl-over-slf4j</module>
<module>log4j-over-slf4j</module>
<module>jul-to-slf4j</module>
<module>osgi-over-slf4j</module>
<module>integration</module>
<module>slf4j-site</module>
<module>slf4j-migrator</module>
Expand Down

0 comments on commit d6205bf

Please sign in to comment.