Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A27F910F34 for ; Tue, 25 Feb 2014 08:56:37 +0000 (UTC) Received: (qmail 98630 invoked by uid 500); 25 Feb 2014 08:56:36 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 98550 invoked by uid 500); 25 Feb 2014 08:56:32 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 98530 invoked by uid 99); 25 Feb 2014 08:56:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Feb 2014 08:56:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Feb 2014 08:56:28 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DA6CD238896F; Tue, 25 Feb 2014 08:56:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: chetanm@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140225085606.DA6CD238896F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 statusList = logbackManager.getStatusManager().getCopyOfStatusList(); pw.println("Logback Status"); pw.println("--------------------------------------------------");