incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1571618 - /sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingConfigurationPrinter.java
Date Tue, 25 Feb 2014 08:56:06 GMT
Author: chetanm
Date: Tue Feb 25 08:56:06 2014
New Revision: 1571618

URL: http://svn.apache.org/r1571618
Log:
SLING-3364 - All rotated log files are not made part of the zip provided through webconsole

Added support which uses logic similar to one used in earlier Sling Log implementations whereby
rotated files present in same directory would be included

Modified:
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/SlingConfigurationPrinter.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=1571618&r1=1571617&r2=1571618&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
Tue Feb 25 08:56:06 2014
@@ -20,6 +20,7 @@ package org.apache.sling.commons.log.log
 
 import java.io.File;
 import java.io.FileReader;
+import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.net.MalformedURLException;
@@ -30,6 +31,7 @@ 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.rolling.RollingFileAppender;
 import ch.qos.logback.core.status.Status;
 import ch.qos.logback.core.util.CachingDateFormatter;
 
@@ -38,7 +40,7 @@ import ch.qos.logback.core.util.CachingD
  * plugin to display the currently configured log files.
  */
 public class SlingConfigurationPrinter {
-    private final CachingDateFormatter SDF = new CachingDateFormatter("yyyy-MM-dd HH:mm:ss");
+    private static final CachingDateFormatter SDF = new CachingDateFormatter("yyyy-MM-dd
HH:mm:ss");
     private final LogbackManager logbackManager;
 
     public SlingConfigurationPrinter(LogbackManager logbackManager) {
@@ -73,7 +75,7 @@ public class SlingConfigurationPrinter {
                         if (fr != null) {
                             try {
                                 fr.close();
-                            } catch (IOException ignoreCloseException) {
+                            } catch (IOException ignored) {
                             }
                         }
                     }
@@ -84,8 +86,10 @@ public class SlingConfigurationPrinter {
     }
 
     /**
-     * TODO Need to see how to implement this with LogBack as we cannot get
-     * information about all rolled over policy
+     * Attempts to determine all log files created even via rotation.
+     * if some complex rotation logic is used where rotated file get different names
+     * or get created in different directory then those files would not be
+     * included
      * 
      * @see org.apache.felix.webconsole.AttachmentProvider#getAttachments(String)
      */
@@ -97,15 +101,7 @@ public class SlingConfigurationPrinter {
             LogbackManager.LoggerStateContext ctx = logbackManager.determineLoggerState();
             for (Appender<ILoggingEvent> appender : ctx.getAllAppenders()) {
                 if (appender instanceof FileAppender) {
-                    final File file = new File(((FileAppender) appender).getFile());
-                    // TODO With LogBack there is no straightforward way to get
-                    // information
-                    // about rolled over files
-                    // final File[] files =
-                    // writer.getFileRotator().getRotatedFiles(writer.getFile());
-                    final File[] files = new File[] {
-                        file
-                    };
+                    final File[] files = getRotatedFiles((FileAppender) appender);
                     for (File f : files) {
                         try {
                             urls.add(f.toURI().toURL());
@@ -122,7 +118,28 @@ public class SlingConfigurationPrinter {
         return null;
     }
 
-    private void dumpLogbackStatus(LogbackManager logbackManager, PrintWriter pw) {
+    private static File[] getRotatedFiles(FileAppender app) {
+        final File file = new File(app.getFile());
+
+        //If RollingFileAppender then make an attempt to list files
+        //This might not work in all cases if complex rolling patterns
+        //are used in Logback
+        if (app instanceof RollingFileAppender) {
+            final File dir = file.getParentFile();
+            final String baseName = file.getName();
+            return dir.listFiles(new FilenameFilter() {
+                public boolean accept(File dir, String name) {
+                    return name.startsWith(baseName);
+                }
+            });
+        }
+
+        //Not a RollingFileAppender then just return the actual file
+        return new File[]{file};
+    }
+
+    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+    private static void dumpLogbackStatus(LogbackManager logbackManager, PrintWriter pw)
{
         List<Status> statusList = logbackManager.getStatusManager().getCopyOfStatusList();
         pw.println("Logback Status");
         pw.println("--------------------------------------------------");



Mime
View raw message