Author: fmeschbe
Date: Thu Jul 23 12:32:31 2009
New Revision: 797041

URL: http://svn.apache.org/viewvc?rev=797041&view=rev
Log:
SLING-1062 Add web console plugin (requires post 1.2.10 trunk build
or later web console for best results)

Added:
    
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java
   (with props)
Modified:
    sling/trunk/bundles/commons/log/pom.xml
    
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
    
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/FileRotator.java
    
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/ScheduledFileRotator.java
    
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SizeLimitedFileRotator.java

Modified: sling/trunk/bundles/commons/log/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/pom.xml?rev=797041&r1=797040&r2=797041&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/pom.xml (original)
+++ sling/trunk/bundles/commons/log/pom.xml Thu Jul 23 12:32:31 2009
@@ -71,6 +71,10 @@
                             org.slf4j.helpers, org.slf4j.impl,
                             org.slf4j.spi
                         </Private-Package>
+                        <Import-Package>
+                            javax.servlet.*;resolution:=optional,
+                            *
+                        </Import-Package>
                     </instructions>
                 </configuration>
             </plugin>
@@ -126,6 +130,12 @@
             <optional>true</optional>
         </dependency>
         
+        <!-- servlet API for the web console plugin -->
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
+        
         <!-- testing -->
         <dependency>
             <groupId>junit</groupId>

Modified: 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java?rev=797041&r1=797040&r2=797041&view=diff
==============================================================================
--- 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
 (original)
+++ 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/LogManager.java
 Thu Jul 23 12:32:31 2009
@@ -20,6 +20,7 @@
 import java.util.Hashtable;
 
 import org.apache.sling.commons.log.internal.slf4j.LogConfigManager;
+import org.apache.sling.commons.log.internal.slf4j.SlingLogPanel;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
@@ -50,10 +51,10 @@
     public static final String LOG_LOGGERS = 
"org.apache.sling.commons.log.names";
 
     public static final String LOG_LEVEL_DEFAULT = "INFO";
-    
+
     public static final int LOG_FILE_NUMBER_DEFAULT = 5;
 
-    public static final String LOG_FILE_SIZE_DEFAULT = "10M";
+    public static final String LOG_FILE_SIZE_DEFAULT = "'.'yyyy-MM-dd";
 
     public static final String PID = "org.apache.sling.commons.log.LogManager";
 
@@ -115,9 +116,24 @@
         props.put(Constants.SERVICE_DESCRIPTION, msf.getName());
         configConfigurer = context.registerService(
             ManagedServiceFactory.class.getName(), msf, props);
+
+        // setup the web console plugin panel. This may fail loading
+        // the panel class if the Servlet API is not wired
+        try {
+            SlingLogPanel.registerPanel(context);
+        } catch (Throwable ignore) {
+        }
     }
 
     void shutdown() {
+
+        // tear down the web console plugin panel (if created at all). This
+        // may fail loading the panel class if the Servlet API is not wired
+        try {
+             SlingLogPanel.unregisterPanel();
+        } catch (Throwable ignore) {
+        }
+
         if (loggingConfigurable != null) {
             loggingConfigurable.unregister();
             loggingConfigurable = null;
@@ -156,7 +172,7 @@
         if (config.get(LOG_LEVEL) == null) {
             config.put(LOG_LEVEL, LOG_LEVEL_DEFAULT);
         }
-        
+
         return config;
     }
 
@@ -180,7 +196,7 @@
             if (properties == null) {
                 properties = defaultConfiguration;
             }
-            
+
             // set the logger name to a special value to indicate the global
             // (ROOT) logger setting (SLING-529)
             properties.put(LOG_LOGGERS, LogConfigManager.ROOT);

Modified: 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/FileRotator.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/FileRotator.java?rev=797041&r1=797040&r2=797041&view=diff
==============================================================================
--- 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/FileRotator.java
 (original)
+++ 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/FileRotator.java
 Thu Jul 23 12:32:31 2009
@@ -42,6 +42,11 @@
         public void rotate(File file) {
             // no rotation
         }
+
+        @Override
+        public String toString() {
+            return "NullRotator";
+        }
     };
 
     /**

Modified: 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/ScheduledFileRotator.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/ScheduledFileRotator.java?rev=797041&r1=797040&r2=797041&view=diff
==============================================================================
--- 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/ScheduledFileRotator.java
 (original)
+++ 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/ScheduledFileRotator.java
 Thu Jul 23 12:32:31 2009
@@ -270,6 +270,11 @@
         return TOP_OF_TROUBLE; // Deliberately head for trouble...
     }
 
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + ": datePattern" + getDatePattern();
+    }
+
     /**
      * RollingCalendar is a helper class to DailyRollingFileAppender. Given a
      * periodicity type and the current time, it computes the start of the next

Modified: 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SizeLimitedFileRotator.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SizeLimitedFileRotator.java?rev=797041&r1=797040&r2=797041&view=diff
==============================================================================
--- 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SizeLimitedFileRotator.java
 (original)
+++ 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SizeLimitedFileRotator.java
 Thu Jul 23 12:32:31 2009
@@ -117,4 +117,9 @@
         }
     }
 
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + ": maxSize=" + getMaxSize()
+            + ", generations=" + (getMaxIndex() + 1);
+    }
 }
\ No newline at end of file

Added: 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java?rev=797041&view=auto
==============================================================================
--- 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java
 (added)
+++ 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java
 Thu Jul 23 12:32:31 2009
@@ -0,0 +1,143 @@
+/*
+ * 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.sling.commons.log.internal.slf4j;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class SlingLogPanel extends HttpServlet {
+
+    private static final long serialVersionUID = 1L;
+
+    private static ServiceRegistration panelRegistration;
+
+    public static void registerPanel(BundleContext ctx) {
+        if (panelRegistration == null) {
+            Dictionary<String, Object> props = new Hashtable<String, Object>();
+            props.put("felix.webconsole.label", "slinglog");
+            props.put("felix.webconsole.title", "Sling Log Support");
+
+            SlingLogPanel panel = new SlingLogPanel();
+            panelRegistration = ctx.registerService("javax.servlet.Servlet",
+                panel, props);
+        }
+    }
+
+    public static void unregisterPanel() {
+        if (panelRegistration != null) {
+            panelRegistration.unregister();
+            panelRegistration = null;
+        }
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+            throws IOException {
+
+        final PrintWriter pw = resp.getWriter();
+        final LogConfigManager logConfigManager = 
LogConfigManager.getInstance();
+
+        pw.println("<div class='table'>");
+
+        pw.println("<h1>Logger</h1>");
+
+        pw.println("<table class='tablelayout'>");
+
+        pw.println("<thead>");
+        pw.println("</tr>");
+        pw.println("<tr>");
+        pw.println("<th>PID</th>");
+        pw.println("<th>Log Level</th>");
+        pw.println("<th>Log File</th>");
+        pw.println("<th>Logger</th>");
+        pw.println("</tr>");
+        pw.println("</thead>");
+        pw.println("<tbody>");
+
+        Iterator<SlingLoggerConfig> loggers = 
logConfigManager.getSlingLoggerConfigs();
+        while (loggers.hasNext()) {
+            final SlingLoggerConfig logger = loggers.next();
+            pw.println("<tr>");
+            pw.println("<td>" + logger.getConfigPid() + "</td>");
+            pw.println("<td>" + logger.getLogLevel() + "</td>");
+            pw.println("<td>" + getPath(logger.getLogWriter()) + "</td>");
+
+            pw.println("<td>");
+            String sep = "";
+            for (String cat : logger.getCategories()) {
+                pw.print(sep);
+                pw.println(cat);
+                sep = "<br />";
+            }
+            pw.println("</td>");
+            pw.println("</tr>");
+        }
+
+        pw.println("</tbody>");
+        pw.println("</table>");
+        pw.println("</div>");
+
+        pw.println("<div class='table'>");
+
+        pw.println("<h1>Log Writer</h1>");
+
+        pw.println("<table class='tablelayout'>");
+
+        pw.println("<thead>");
+        pw.println("<tr>");
+        pw.println("<th>PID</th>");
+        pw.println("<th>Log File</th>");
+        pw.println("<th>Rotator</th>");
+        pw.println("</tr>");
+        pw.println("</thead>");
+        pw.println("<tbody>");
+
+        Iterator<SlingLoggerWriter> writers = 
logConfigManager.getSlingLoggerWriters();
+        while (writers.hasNext()) {
+            final SlingLoggerWriter writer = writers.next();
+            final String pid = (writer.getConfigurationPID() != null)
+                    ? writer.getConfigurationPID()
+                    : "[implicit]";
+            pw.println("<tr>");
+            pw.println("<td>" + pid + "</td>");
+            pw.println("<td>" + getPath(writer) + "</td>");
+            pw.println("<td>" + writer.getFileRotator() + "</td>");
+            pw.println("</tr>");
+        }
+
+        pw.println("</tbody>");
+        pw.println("</table>");
+        pw.println("</div>");
+    }
+
+    private static String getPath(SlingLoggerWriter writer) {
+        final String path = writer.getPath();
+        return (path != null) ? path : "[stdout]";
+    }
+}

Propchange: 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url


Reply via email to