Added more robust logging.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@818555 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/whiteboard/pom.xml b/http/whiteboard/pom.xml
index 1b49f15..888a0cc 100644
--- a/http/whiteboard/pom.xml
+++ b/http/whiteboard/pom.xml
@@ -42,6 +42,7 @@
                             org.apache.felix.http.whiteboard.internal.WhiteboardActivator
                         </Bundle-Activator>
                         <Private-Package>
+                            org.apache.felix.http.base.*,
                             org.apache.felix.http.whiteboard.*
                         </Private-Package>
                         <Import-Package>
@@ -72,6 +73,12 @@
             <version>${pom.version}</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>${pom.groupId}</groupId>
+            <artifactId>org.apache.felix.http.base</artifactId>
+            <version>${pom.version}</version>
+            <scope>provided</scope>
+        </dependency>        
     </dependencies>
 
 </project>
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
index 0ffb830..43ec224 100644
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
+++ b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
@@ -16,8 +16,6 @@
  */
 package org.apache.felix.http.whiteboard.internal;
 
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
 import org.osgi.util.tracker.ServiceTracker;
 import org.apache.felix.http.whiteboard.internal.tracker.FilterTracker;
 import org.apache.felix.http.whiteboard.internal.tracker.HttpContextTracker;
@@ -25,11 +23,11 @@
 import org.apache.felix.http.whiteboard.internal.tracker.HttpServiceTracker;
 import org.apache.felix.http.whiteboard.internal.manager.ExtenderManagerImpl;
 import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
-import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.AbstractActivator;
 import java.util.ArrayList;
 
 public final class WhiteboardActivator
-    implements BundleActivator
+    extends AbstractActivator
 {
     private final ArrayList<ServiceTracker> trackers;
     private ExtenderManager manager;
@@ -39,15 +37,14 @@
         this.trackers = new ArrayList<ServiceTracker>();
     }
 
-    public void start(BundleContext context)
+    protected void doStart()
         throws Exception
     {
-        SystemLogger.get().open(context);
         this.manager = new ExtenderManagerImpl();
-        addTracker(new HttpContextTracker(context, this.manager));
-        addTracker(new FilterTracker(context, this.manager));
-        addTracker(new ServletTracker(context, this.manager));
-        addTracker(new HttpServiceTracker(context, this.manager));
+        addTracker(new HttpContextTracker(getBundleContext(), this.manager));
+        addTracker(new FilterTracker(getBundleContext(), this.manager));
+        addTracker(new ServletTracker(getBundleContext(), this.manager));
+        addTracker(new HttpServiceTracker(getBundleContext(), this.manager));
     }
 
     private void addTracker(ServiceTracker tracker)
@@ -56,7 +53,7 @@
         tracker.open();
     }
 
-    public void stop(BundleContext context)
+    protected void doStop()
         throws Exception
     {
         for (ServiceTracker tracker : this.trackers) {
@@ -65,6 +62,5 @@
 
         this.trackers.clear();
         this.manager.unregisterAll();
-        SystemLogger.get().close();
     }
 }
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java
index e144e1e..063116b 100644
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java
+++ b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java
@@ -22,7 +22,7 @@
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.apache.felix.http.api.ExtHttpService;
-import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
 
 import javax.servlet.Servlet;
 import javax.servlet.Filter;
@@ -141,9 +141,9 @@
     {
         this.httpService = service;
         if (this.httpService instanceof ExtHttpService) {
-            SystemLogger.get().info("Detected extended HttpService. Filters enabled.");
+            SystemLogger.info("Detected extended HttpService. Filters enabled.");
         } else {
-            SystemLogger.get().info("Standard HttpService. Filters disabled.");
+            SystemLogger.info("Standard HttpService. Filters disabled.");
         }
 
         registerAll();
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java
index bcccc0a..8ae62b4 100644
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java
+++ b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java
@@ -19,7 +19,8 @@
 import org.osgi.service.http.HttpService;
 import org.osgi.service.http.HttpContext;
 import org.apache.felix.http.api.ExtHttpService;
-import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+
 import javax.servlet.Filter;
 
 public final class FilterMapping
@@ -49,7 +50,7 @@
         try {
             httpService.registerFilter(this.filter, this.pattern, getInitParams(), ranking, getContext());
         } catch (Exception e) {
-            SystemLogger.get().error("Failed to register filter", e);
+            SystemLogger.error("Failed to register filter", e);
         }
     }
 
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java
index d44056e..e5f105e 100644
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java
+++ b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java
@@ -18,7 +18,7 @@
 
 import org.osgi.framework.Bundle;
 import org.osgi.service.http.HttpContext;
-import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
 import java.util.HashMap;
 
 public final class HttpContextManager
@@ -46,9 +46,9 @@
             context = new DefaultHttpContext(bundle);
             this.idMap.put(id, context);
             this.contextMap.put(context, id);
-            SystemLogger.get().debug("Added context with id [" + contextId + "]");
+            SystemLogger.debug("Added context with id [" + contextId + "]");
         } else {
-            SystemLogger.get().debug("Reusing context with id [" + contextId + "]");            
+            SystemLogger.debug("Reusing context with id [" + contextId + "]");            
         }
 
         return context;
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java
index 408c58d..0a283e9 100644
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java
+++ b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java
@@ -18,7 +18,8 @@
 
 import org.osgi.service.http.HttpService;
 import org.osgi.service.http.HttpContext;
-import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+
 import javax.servlet.Servlet;
 
 public final class ServletMapping
@@ -39,7 +40,7 @@
         try {
             httpService.registerServlet(this.alias, this.servlet, getInitParams(), getContext());
         } catch (Exception e) {
-            SystemLogger.get().error("Failed to register servlet", e);
+            SystemLogger.error("Failed to register servlet", e);
         }
     }
 
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/SystemLogger.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/SystemLogger.java
deleted file mode 100644
index df68069..0000000
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/SystemLogger.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.felix.http.whiteboard.internal.util;
-
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
-
-public final class SystemLogger
-{
-    private final static SystemLogger INSTANCE =
-        new SystemLogger();
-    
-    private ServiceTracker tracker;
-
-    private SystemLogger()
-    {
-    }
-
-    public void open(BundleContext context)
-    {
-        this.tracker = new ServiceTracker(context, LogService.class.getName(), null);
-        this.tracker.open();
-    }
-
-    public void close()
-    {
-        this.tracker.close();
-    }
-
-    public void debug(String message)
-    {
-        log(LogService.LOG_DEBUG, message, null);
-    }
-
-    public void info(String message)
-    {
-        log(LogService.LOG_INFO, message, null);
-    }
-
-    public void warning(String message, Throwable cause)
-    {
-        log(LogService.LOG_WARNING, message, cause);
-    }
-
-    public void error(String message, Throwable cause)
-    {
-        log(LogService.LOG_ERROR, message, cause);
-    }
-
-    private void log(int level, String message, Throwable cause)
-    {
-        LogService log = (LogService)this.tracker.getService();
-        if (log != null) {
-            log.log(level, message, cause);
-        } else {
-            System.out.println(message);
-            if (cause != null) {
-                cause.printStackTrace(System.out);
-            }
-        }
-    }
-
-    public static SystemLogger get()
-    {
-        return INSTANCE;
-    }
-}
\ No newline at end of file