FELIX-4870 : sslfilter implementation assumes there is only one log service

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1676459 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/LogServiceTracker.java b/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/LogServiceTracker.java
index ab06dbb..8f1effd 100644
--- a/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/LogServiceTracker.java
+++ b/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/LogServiceTracker.java
@@ -18,35 +18,55 @@
  */
 package org.apache.felix.http.sslfilter.internal;
 
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeMap;
+
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.ServiceTracker;
 
 /**
- * TODO - this implementation assumes that there is exactly one LogService
+ *
  *
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class LogServiceTracker extends ServiceTracker
 {
+    private final Map<ServiceReference, LogService> logServices = new TreeMap<ServiceReference, LogService>(Collections.reverseOrder());
+
     public LogServiceTracker(BundleContext context)
     {
         super(context, LogService.class.getName(), null);
     }
 
     @Override
-    public Object addingService(ServiceReference reference)
+    public Object addingService(final ServiceReference reference)
     {
-        LogService result = (LogService) super.addingService(reference);
-        SystemLogger.setLogService(result);
+        final LogService result = (LogService) super.addingService(reference);
+        if ( result != null ) {
+            synchronized ( logServices ) {
+                logServices.put(reference, result);
+                SystemLogger.setLogService(logServices.values().iterator().next());
+            }
+        }
         return result;
     }
 
     @Override
-    public void removedService(ServiceReference reference, Object service)
+    public void removedService(final ServiceReference reference, final Object service)
     {
-        SystemLogger.setLogService(null);
+        synchronized ( logServices ) {
+            logServices.remove(reference);
+            final Collection<LogService> services = logServices.values();
+            if ( services.isEmpty() ) {
+                SystemLogger.setLogService(null);
+            } else {
+                SystemLogger.setLogService(services.iterator().next());
+            }
+        }
         super.removedService(reference, service);
     }
 }