felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1220720 - /felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
Date Mon, 19 Dec 2011 12:39:00 GMT
Author: fmeschbe
Date: Mon Dec 19 12:38:59 2011
New Revision: 1220720

URL: http://svn.apache.org/viewvc?rev=1220720&view=rev
Log:
FELIX-3284 Improve logging to write to stderr if servlet context is not available yet (before
init) or anymore (after destroy)

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java?rev=1220720&r1=1220719&r2=1220720&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
Mon Dec 19 12:38:59 2011
@@ -24,6 +24,8 @@ import java.net.URLConnection;
 import java.util.*;
 import java.util.Map.Entry;
 
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.*;
 
@@ -377,13 +379,16 @@ public abstract class AbstractWebConsole
 
 
     /**
-     * Calls the <code>GenericServlet.log(String)</code> method if the
+     * Calls the <code>ServletContext.log(String)</code> method if the
      * configured log level is less than or equal to the given <code>level</code>.
      * <p>
      * Note, that the <code>level</code> paramter is only used to decide whether
      * the <code>GenericServlet.log(String)</code> method is called or not. The
      * actual implementation of the <code>GenericServlet.log</code> method is
      * outside of the control of this method.
+     * <p>
+     * If the servlet has not been initialized yet or has already been destroyed
+     * the message is printed to stderr.
      *
      * @param level The log level at which to log the message
      * @param message The message to log
@@ -392,13 +397,24 @@ public abstract class AbstractWebConsole
     {
         if ( logLevel >= level )
         {
-            log( message );
+            ServletConfig config = getServletConfig();
+            if ( config != null )
+            {
+                ServletContext context = config.getServletContext();
+                if ( context != null )
+                {
+                    context.log( message );
+                    return;
+                }
+            }
+
+            System.err.println( message );
         }
     }
 
 
     /**
-     * Calls the <code>GenericServlet.log(String, Throwable)</code> method if
+     * Calls the <code>ServletContext.log(String, Throwable)</code> method if
      * the configured log level is less than or equal to the given
      * <code>level</code>.
      * <p>
@@ -415,7 +431,22 @@ public abstract class AbstractWebConsole
     {
         if ( logLevel >= level )
         {
-            log( message, t );
+            ServletConfig config = getServletConfig();
+            if ( config != null )
+            {
+                ServletContext context = config.getServletContext();
+                if ( context != null )
+                {
+                    context.log( message, t );
+                    return;
+                }
+            }
+
+            System.err.println( message );
+            if ( t != null )
+            {
+                t.printStackTrace( System.err );
+            }
         }
     }
 



Mime
View raw message