Return-Path: X-Original-To: apmail-logging-commits-archive@minotaur.apache.org Delivered-To: apmail-logging-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ABC5698DD for ; Thu, 30 Aug 2012 06:35:06 +0000 (UTC) Received: (qmail 41268 invoked by uid 500); 30 Aug 2012 06:35:06 -0000 Delivered-To: apmail-logging-commits-archive@logging.apache.org Received: (qmail 41231 invoked by uid 500); 30 Aug 2012 06:35:05 -0000 Mailing-List: contact commits-help@logging.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@logging.apache.org Delivered-To: mailing list commits@logging.apache.org Received: (qmail 40849 invoked by uid 99); 30 Aug 2012 06:35:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Aug 2012 06:35:04 +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; Thu, 30 Aug 2012 06:35:01 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5C0882388900; Thu, 30 Aug 2012 06:34:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1378813 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/ core/src/test/java/org/apache/logging/log4j/core/appender/rolling/ core/src/test/resources/ src/changes/ Date: Thu, 30 Aug 2012 06:34:17 -0000 To: commits@logging.apache.org From: rgoers@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120830063417.5C0882388900@eris.apache.org> Author: rgoers Date: Thu Aug 30 06:34:16 2012 New Revision: 1378813 URL: http://svn.apache.org/viewvc?rev=1378813&view=rev Log: Fix for LOG4J2-71 Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/FileRenameAction.java logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeTest.java logging/log4j/log4j2/trunk/core/src/test/resources/log4j-rolling3.xml logging/log4j/log4j2/trunk/src/changes/changes.xml Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/FileRenameAction.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/FileRenameAction.java?rev=1378813&r1=1378812&r2=1378813&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/FileRenameAction.java (original) +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/helper/FileRenameAction.java Thu Aug 30 06:34:16 2012 @@ -16,6 +16,9 @@ */ package org.apache.logging.log4j.core.appender.rolling.helper; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.status.StatusLogger; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -27,6 +30,9 @@ import java.nio.channels.FileChannel; * File rename action. */ public final class FileRenameAction extends ActionBase { + + private static final Logger LOGGER = StatusLogger.getLogger(); + /** * Source. */ @@ -74,17 +80,31 @@ public final class FileRenameAction exte */ public static boolean execute(final File source, final File destination, boolean renameEmptyFiles) { if (renameEmptyFiles || (source.length() > 0)) { + File parent = destination.getParentFile(); + if (!parent.exists()) { + if (!parent.mkdirs()) { + LOGGER.error("Unable to create directory {}", parent.getAbsolutePath()); + return false; + } + } try { - - boolean result = source.renameTo(destination); - //System.out.println("Rename of " + source.getName() + " to " + destination.getName() + ": " + result); - return result; + if (!source.renameTo(destination)) { + try { + copyFile(source, destination); + return source.delete(); + } catch (IOException iex) { + LOGGER.error("Unable to rename file {} to {} - {}", source.getAbsolutePath(), + destination.getAbsolutePath(), iex.getMessage()); + } + } + return true; } catch (Exception ex) { try { copyFile(source, destination); return source.delete(); } catch (IOException iex) { - iex.printStackTrace(); + LOGGER.error("Unable to rename file {} to {} - {}", source.getAbsolutePath(), + destination.getAbsolutePath(), iex.getMessage()); } } } Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeTest.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeTest.java?rev=1378813&r1=1378812&r2=1378813&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeTest.java (original) +++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderTimeAndSizeTest.java Thu Aug 30 06:34:16 2012 @@ -35,7 +35,7 @@ import static org.junit.Assert.assertTru public class RollingAppenderTimeAndSizeTest { private static final String CONFIG = "log4j-rolling3.xml"; - private static final String DIR = "target/rolling3"; + private static final String DIR = "target/rolling3/test"; org.apache.logging.log4j.Logger logger = LogManager.getLogger(RollingAppenderTimeAndSizeTest.class.getName()); @@ -49,7 +49,7 @@ public class RollingAppenderTimeAndSizeT @AfterClass public static void cleanupClass() { - deleteDir(); + //deleteDir(); System.clearProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY); LoggerContext ctx = (LoggerContext) LogManager.getContext(); ctx.reconfigure(); Modified: logging/log4j/log4j2/trunk/core/src/test/resources/log4j-rolling3.xml URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-rolling3.xml?rev=1378813&r1=1378812&r2=1378813&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/core/src/test/resources/log4j-rolling3.xml (original) +++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j-rolling3.xml Thu Aug 30 06:34:16 2012 @@ -26,7 +26,7 @@ - + %d %p %C{1.} [%t] %m%n Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1378813&r1=1378812&r2=1378813&view=diff ============================================================================== --- logging/log4j/log4j2/trunk/src/changes/changes.xml (original) +++ logging/log4j/log4j2/trunk/src/changes/changes.xml Thu Aug 30 06:34:16 2012 @@ -26,6 +26,9 @@ Update the versions of SLF4J and Logback. + + FileRenameAction did not create the parent directories of the archive files causing the rollover to fail. +