incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1563820 - in /sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal: SlingConfigurationPrinter.java SlingLogPanel.java
Date Mon, 03 Feb 2014 10:12:40 GMT
Author: chetanm
Date: Mon Feb  3 10:12:40 2014
New Revision: 1563820

URL: http://svn.apache.org/r1563820
Log:
SLING-3363 - Make Logback status part of Configuration Printer output

Modified:
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingConfigurationPrinter.java
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingLogPanel.java

Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingConfigurationPrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingConfigurationPrinter.java?rev=1563820&r1=1563819&r2=1563820&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingConfigurationPrinter.java
(original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingConfigurationPrinter.java
Mon Feb  3 10:12:40 2014
@@ -30,12 +30,15 @@ import java.util.List;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.Appender;
 import ch.qos.logback.core.FileAppender;
+import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.util.CachingDateFormatter;
 
 /**
  * The <code>SlingConfigurationPrinter</code> is an Apache Felix Web Console
  * plugin to display the currently configured log files.
  */
 public class SlingConfigurationPrinter {
+    private final CachingDateFormatter SDF = new CachingDateFormatter("yyyy-MM-dd HH:mm:ss");
     private final LogbackManager logbackManager;
 
     public SlingConfigurationPrinter(LogbackManager logbackManager) {
@@ -48,6 +51,7 @@ public class SlingConfigurationPrinter {
     @SuppressWarnings("UnusedDeclaration")
     public void printConfiguration(PrintWriter printWriter) {
         LogbackManager.LoggerStateContext ctx = logbackManager.determineLoggerState();
+        dumpLogbackStatus(logbackManager, printWriter);
         for (Appender<ILoggingEvent> appender : ctx.getAllAppenders()) {
             if (appender instanceof FileAppender) {
                 final File file = new File(((FileAppender) appender).getFile());
@@ -118,4 +122,34 @@ public class SlingConfigurationPrinter {
         return null;
     }
 
+    private void dumpLogbackStatus(LogbackManager logbackManager, PrintWriter pw) {
+        List<Status> statusList = logbackManager.getStatusManager().getCopyOfStatusList();
+        pw.println("Logback Status");
+        pw.println("--------------------------------------------------");
+        for (Status s : statusList) {
+            pw.printf("%s *%s* %s - %s %n",
+                    SDF.format(s.getDate()),
+                    statusLevelAsString(s),
+                    SlingLogPanel.abbreviatedOrigin(s),
+                    s.getMessage());
+            if (s.getThrowable() != null) {
+                s.getThrowable().printStackTrace(pw);
+            }
+        }
+
+        pw.println();
+    }
+
+    private static String statusLevelAsString(Status s) {
+        switch (s.getEffectiveLevel()) {
+            case Status.INFO:
+                return "INFO";
+            case Status.WARN:
+                return "WARN";
+            case Status.ERROR:
+                return "ERROR";
+        }
+        return null;
+    }
+
 }

Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingLogPanel.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingLogPanel.java?rev=1563820&r1=1563819&r2=1563820&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingLogPanel.java
(original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingLogPanel.java
Mon Feb  3 10:12:40 2014
@@ -736,7 +736,7 @@ public class SlingLogPanel extends HttpS
         return null;
     }
 
-    private static String abbreviatedOrigin(Status s) {
+    static String abbreviatedOrigin(Status s) {
         Object o = s.getOrigin();
         if (o == null) {
             return null;



Mime
View raw message