You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2013/08/07 13:50:27 UTC

svn commit: r1511270 [2/2] - in /sling/whiteboard/fmeschbe/logback: ./ src/main/java/org/apache/sling/commons/log/internal/ src/main/java/org/apache/sling/commons/log/internal/config/ src/main/java/org/apache/sling/commons/log/internal/config/logback/ ...

Added: sling/whiteboard/fmeschbe/logback/src/main/java/org/apache/sling/commons/log/internal/config/logback/SlingLogPanel.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/logback/src/main/java/org/apache/sling/commons/log/internal/config/logback/SlingLogPanel.java?rev=1511270&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/logback/src/main/java/org/apache/sling/commons/log/internal/config/logback/SlingLogPanel.java (added)
+++ sling/whiteboard/fmeschbe/logback/src/main/java/org/apache/sling/commons/log/internal/config/logback/SlingLogPanel.java Wed Aug  7 11:50:26 2013
@@ -0,0 +1,200 @@
+/*
+ * 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.config.logback;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * The <code>SlingLogPanel</code> is a Felix Web Console plugin to display the
+ * current active log bundle configuration.
+ * <p>
+ * In future revisions of this plugin, the configuration may probably even
+ * be modified through this panel.
+ */
+public class SlingLogPanel extends HttpServlet {
+
+    private static final long serialVersionUID = 1L;
+
+    private final LogConfigManager logConfigManager;
+
+    public SlingLogPanel(final LogConfigManager logConfigManager) {
+        this.logConfigManager = logConfigManager;
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+            throws IOException {
+
+        final PrintWriter pw = resp.getWriter();
+        final LogConfigManager logConfigManager = this.logConfigManager;
+
+        final String consoleAppRoot = (String) req.getAttribute("felix.webconsole.appRoot");
+        final String cfgColTitle = (consoleAppRoot == null) ? "PID" : "Configuration";
+
+
+        pw.printf(
+            "<p class='statline'>Log Service Stats: %d categories, %d configuration(s), %d writer(s)</p>%n",
+            logConfigManager.getNumLoggers(),
+            logConfigManager.getNumSlingLoggerConfigs(),
+            logConfigManager.getNumSlingLogWriters());
+
+        pw.println("<div class='table'>");
+
+        pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>");
+        pw.println("  <span style=\"float: left; margin-left: 1em\">Logger</span>");
+        pw.println("  &nbsp;"); // make sure div has a height
+        pw.println("</div>");
+
+        pw.println("<table class='nicetable ui-widget'>");
+
+        pw.println("<thead class='ui-widget-header'>");
+        pw.println("<tr>");
+        pw.println("<th>Log Level</th>");
+        pw.println("<th>Log File</th>");
+        pw.println("<th>Logger</th>");
+        pw.println("<th>" + cfgColTitle + "</th>");
+        pw.println("</tr>");
+        pw.println("</thead>");
+        pw.println("<tbody class='ui-widget-content'>");
+
+        Iterator<LogConfig> loggers = logConfigManager.getSlingLoggerConfigs();
+        while (loggers.hasNext()) {
+            final LogConfig logger = loggers.next();
+            pw.println("<tr>");
+            pw.println("<td>" + logger.getLogLevel() + "</td>");
+            pw.println("<td>" + getPath(logger.getAppenderKeys()) + "</td>");
+
+            pw.println("<td>");
+            String sep = "";
+            for (String cat : logger.getCategories()) {
+                pw.print(sep);
+                pw.println(cat);
+                sep = "<br />";
+            }
+            pw.println("</td>");
+
+            pw.println("<td>" + formatPid(consoleAppRoot, logger.getConfigPid()) + "</td>");
+            pw.println("</tr>");
+        }
+
+        pw.println("</tbody>");
+        pw.println("</table>");
+        pw.println("</div>");
+
+        pw.println("<div class='table'>");
+
+        pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>");
+        pw.println("  <span style='float: left; margin-left: 1em'>Log Writer</span>");
+        pw.println("  <button class='rotateFiles ui-state-default ui-corner-all' style='min-width: 8em;'>Rotate Logfiles</button>");
+        pw.println("</div>");
+
+        pw.println("<table class='nicetable ui-widget'>");
+
+        pw.println("<thead class='ui-widget-header'>");
+        pw.println("<tr>");
+        pw.println("<th>Log File</th>");
+        pw.println("<th>Rotator</th>");
+        pw.println("<th>" + cfgColTitle + "</th>");
+        pw.println("</tr>");
+        pw.println("</thead>");
+        pw.println("<tbody class='ui-widget-content'>");
+
+        Iterator<LogWriter> writers = logConfigManager.getSlingLoggerWriters();
+        while (writers.hasNext()) {
+            final LogWriter writer = writers.next();
+
+            // writer information
+            pw.println("<tr>");
+            pw.println("<td>" + writer.getFileName() + "</td>");
+            pw.println("<td>" + writer.getLogRotation() + "</td>");
+            pw.println("<td>" + formatPid(consoleAppRoot, writer.getConfigurationPID())
+                + "</td>");
+            pw.println("</tr>");
+
+            // rotated files
+            pw.println("<tr>");
+            pw.println("<td colspan='3'>");
+
+            // TODO: get from appenders !!!
+//            File[] files = writer.getFileRotator().getRotatedFiles(writer.getFile());
+//            for (File file : files) {
+//                pw.printf("%s - %s - %s<br/>%n", file, file.length(), new Date(file.lastModified()));
+//            }
+
+            pw.println("</td>");
+            pw.println("</tr>");
+        }
+
+        pw.println("</tbody>");
+        pw.println("</table>");
+        pw.println("</div>");
+
+        pw.println("<script>");
+        pw.println("$(document).ready(function(){");
+        pw.println("    $('.rotateFiles').click(function(){$.post(pluginRoot, {'action': 'rotateFiles'});});");
+        pw.println("});");
+        pw.println("</script>");
+    }
+
+    @Override
+    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+        String action = req.getParameter("action");
+        if ("rotateFiles".equals(action)) {
+            // unsupported as of now ...
+//            Iterator<LogWriter> writers = logConfigManager.getSlingLoggerWriters();
+//            while (writers.hasNext()) {
+//                writers.next().rotateFile();
+//            }
+        }
+
+        // success
+        resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
+        resp.flushBuffer();
+    }
+
+    private static String getPath(Set<AppenderKey> writer) {
+//        final String path = writer.getPath();
+//        return (path != null) ? path : "[stdout]";
+        return "----unknown----";
+    }
+
+    private static String formatPid(final String consoleAppRoot,
+            final String pid) {
+        if (pid == null) {
+            return "[implicit]";
+        }
+
+        // no recent web console, so just render the pid as the link
+        if (consoleAppRoot == null) {
+            return "<a href=\"configMgr/" + pid + "\">" + pid + "</a>";
+        }
+
+        // recent web console has app root and hence we can use an image
+        return "<a href=\"configMgr/" + pid + "\"><img src=\"" + consoleAppRoot
+            + "/res/imgs/component_configure.png\" border=\"0\" /></a>";
+    }
+}

Added: sling/whiteboard/fmeschbe/logback/src/main/resources/logback.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/logback/src/main/resources/logback.xml?rev=1511270&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/logback/src/main/resources/logback.xml (added)
+++ sling/whiteboard/fmeschbe/logback/src/main/resources/logback.xml Wed Aug  7 11:50:26 2013
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    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.
+-->
+<configuration>
+
+  <appender name="org.apache.sling.commons.log.LogManager" class="ch.qos.logback.core.ConsoleAppender">
+    <!-- encoders are assigned the type
+         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+    <encoder>
+    <!--
+        "{0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}";
+    
+    Message Pattern for formatting the log messages. \
+ This is a java.text.MessageFormat pattern supporting up to six arguments: \
+ {0} The timestamp of type java.util.Date, {1} the log marker, {2} the name \
+ of the current thread, {3} the name of the logger, {4} the debug level and \
+ {5} the actual debug message. If the log call includes a Throwable, the \
+ stacktrace is just appended to the message.
+    
+     -->
+      <pattern>%d{dd.MM.yyyy HH:mm:ss.SSS} *%level* [%thread] %logger %message%n</pattern>
+    </encoder>
+  </appender>
+
+<!-- 
+  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+    <file>${sling.home}/myApp.log</file>
+
+    <encoder>
+      <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
+    </encoder>
+  </appender>
+-->
+
+  <root level="info">
+    <appender-ref ref="org.apache.sling.commons.log.LogManager" />
+  </root>
+</configuration>
\ No newline at end of file