[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.27-9-g2f02bd4

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Thu Jan 13 23:26:43 CET 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  2f02bd43fd41dca2a6d0592edbae6968d2080b27 (commit)
      from  b6a42b6c46c6bff01f471c8df9bd9beb0a299f10 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=2f02bd43fd41dca2a6d0592edbae6968d2080b27
http://github.com/ceki/logback/commit/2f02bd43fd41dca2a6d0592edbae6968d2080b27

commit 2f02bd43fd41dca2a6d0592edbae6968d2080b27
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Thu Jan 13 23:21:16 2011 +0100

    ongoing work on LBCORE-188 and LBCORE-185

diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RenameUtil.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RenameUtil.java
index c609cc0..8fdd855 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RenameUtil.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RenameUtil.java
@@ -19,6 +19,8 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 
+import ch.qos.logback.core.CoreConstants;
+import ch.qos.logback.core.rolling.RollingFileAppender;
 import ch.qos.logback.core.rolling.RolloverFailure;
 import ch.qos.logback.core.spi.ContextAwareBase;
 import ch.qos.logback.core.util.FileUtil;
@@ -31,6 +33,7 @@ import ch.qos.logback.core.util.FileUtil;
  */
 public class RenameUtil extends ContextAwareBase {
 
+  static String RENAMING_ERROR_URL = CoreConstants.CODES_URL+"#renamingError";
 
   /**
    * A robust file renaming method which in case of failure falls back to
@@ -59,8 +62,9 @@ public class RenameUtil extends ContextAwareBase {
 
       if (!result) {
         addWarn("Failed to rename file [" + fromFile + "] to [" + toFile + "].");
-        addWarn("Attempting to rename by copying.");
-        renameByCopying(from, to);
+        addWarn("Please consider leaving the [file] option of "+ RollingFileAppender.class.getSimpleName()+" empty.");
+        addWarn("See also "+ RENAMING_ERROR_URL);
+
       }
     } else {
       throw new RolloverFailure("File [" + from + "] does not exist.");
diff --git a/logback-core/src/test/java/ch/qos/logback/core/FileAppenderResilienceTest.java b/logback-core/src/test/java/ch/qos/logback/core/FileAppenderResilienceTest.java
index de8d317..fa8ca4b 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/FileAppenderResilienceTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/FileAppenderResilienceTest.java
@@ -91,13 +91,9 @@ class Runner extends RunnableWithCounterAndDone {
     while (!isDone()) {
       counter++;
       fa.doAppend("hello " + counter);
-      if (counter % 1024 == 0) {
-        Thread.yield();//(10);
-
-//        try {
-//          Thread.sleep(10);
-//        } catch (InterruptedException e) {
-//        }
+      if (counter % 512 == 0) {
+        try { Thread.sleep(10);
+        } catch (InterruptedException e) { }
       }
     }
   }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java
index 899a429..fc595fd 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java
@@ -55,56 +55,7 @@ public class RenameUtilTest {
     randomOutputDir.mkdirs();
   }
 
-
-  /**
-   * This test case aims to unit test/reproduce problems encountered while
-   * renaming the log file under windows. However, it is not clear how
-   * the test lives up to this claim.
-   */
-  @Test
-  public void rename() throws Exception {
-    RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
-    rfa.setEncoder(encoder);
-    rfa.setContext(context);
-
-    // rollover by the second
-    String datePattern = "yyyy-MM-dd_HH_mm_ss";
-    SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
-    String[] filenames = new String[2];
-
-    TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
-    tbrp.setFileNamePattern(randomOutputDirAsStr + "test-%d{"
-            + datePattern + "}");
-    tbrp.setContext(context);
-    tbrp.setParent(rfa);
-    tbrp.start();
-
-    TimeBasedFileNamingAndTriggeringPolicy tbnatp = tbrp
-            .getTimeBasedFileNamingAndTriggeringPolicy();
-    tbnatp.setCurrentTime(currentTime);
-
-    rfa.setRollingPolicy(tbrp);
-    rfa.start();
-
-    rfa.doAppend("Hello 0");
-
-    filenames[0] = randomOutputDirAsStr + "test-" + sdf.format(currentTime);
-
-    // set currentTime to next second plus 250 millis
-    currentTime += 1000 - (currentTime % 1000) + 250;
-    tbnatp.setCurrentTime(currentTime);
-
-    rfa.doAppend("Hello 1");
-
-    filenames[1] = randomOutputDirAsStr + "test-" + sdf.format(currentTime);
-
-    for (int i = 0; i < filenames.length; i++) {
-      assertTrue(Compare.compare(filenames[i], CoreTestConstants.TEST_DIR_PREFIX
-              + "witness/rolling/renaming." + i));
-    }
-  }
-
-  @Test
+ @Test
   public void renameToNonExistingDirectory() throws IOException, RolloverFailure {
     RenameUtil renameUtil = new RenameUtil();
     renameUtil.setContext(context);
diff --git a/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRolling2Test.scala b/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRolling2Test.scala
index 6a90b50..eb94065 100644
--- a/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRolling2Test.scala
+++ b/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRolling2Test.scala
@@ -16,10 +16,9 @@ package ch.qos.logback.core.rolling
 import org.junit.Assert.assertTrue
 import org.junit.Before
 import org.junit.Test
-import ch.qos.logback.core.util.Compare
-import ch.qos.logback.core.util.CoreTestConstants
 import ch.qos.logback.core.encoder.EchoEncoder
-import java.io.File
+import java.io.{FileOutputStream, File}
+import ch.qos.logback.core.util.{StatusPrinter, Compare, CoreTestConstants}
 
 class TimeBasedRolling2Test extends RollingScaffolding {
 
@@ -54,7 +53,8 @@ class TimeBasedRolling2Test extends RollingScaffolding {
     rfa.start
   }
 
-  def genericTest(testId: String, compressionSuffix: String, fileOptionIsSet: Boolean, waitDuration: Int): Unit = {
+  type CheckFunction = ((String, Boolean, String) => Unit)
+  def genericTest(checkFunction: CheckFunction)(testId: String, compressionSuffix: String, fileOptionIsSet: Boolean, waitDuration: Int): Unit = {
     val withCompression = compressionSuffix.length > 0
     val fileName = if (fileOptionIsSet) testId2FileName(testId) else null;
     initRFA(rfa1, fileName);
@@ -86,6 +86,13 @@ class TimeBasedRolling2Test extends RollingScaffolding {
       massageExpectedFilesToCorresponToCurrentTarget(testId + ".log")
     }
 
+    checkFunction(testId, withCompression, compressionSuffix)
+  }
+
+  // defaultTest uses the defaultCheck function
+  val defaultTest = genericTest(defaultCheck)_
+
+  def defaultCheck(testId: String, withCompression: Boolean, compressionSuffix:String) = {
     var i = 0;
     for (fn <- expectedFilenameList) {
       val suffix: String = if (withCompression) addGZIfNotLast(i, compressionSuffix) else ""
@@ -93,9 +100,18 @@ class TimeBasedRolling2Test extends RollingScaffolding {
       assertTrue(Compare.compare(fn, witnessFileName));
       i += 1
     }
+  }
+
+  def zCheck(testId: String, withCompression: Boolean, compressionSuffix:String) = {
+    val lastFile = expectedFilenameList.last
+    val witnessFileName: String = CoreTestConstants.TEST_DIR_PREFIX + "witness/rolling/tbr-" + testId
+    println(lastFile+"  "+witnessFileName)
+    assertTrue(Compare.compare(lastFile, witnessFileName));
 
   }
 
+
+
   def doRestart(testId: String, fileOptionIsSet: Boolean, waitDuration: Int) {
     // change the timestamp of the currently actively file
     var activeFile: File = new File(rfa1.getFile)
@@ -120,41 +136,63 @@ class TimeBasedRolling2Test extends RollingScaffolding {
 
   @Test
   def noCompression_FileBlank_NoRestart_1 = {
-    genericTest("test1", "", FILE_OPTION_BLANK, NO_RESTART)
+    defaultTest("test1", "", FILE_OPTION_BLANK, NO_RESTART)
   }
 
   @Test
   def withCompression_FileBlank_NoRestart_2 = {
-    genericTest("test2", ".gz", FILE_OPTION_BLANK, NO_RESTART);
+    defaultTest("test2", ".gz", FILE_OPTION_BLANK, NO_RESTART);
   }
 
   @Test
   def noCompression_FileBlank_StopRestart_3 = {
-    genericTest("test3", "", FILE_OPTION_BLANK, WITH_RESTART);
+    defaultTest("test3", "", FILE_OPTION_BLANK, WITH_RESTART);
   }
 
   @Test
   def noCompression_FileSet_StopRestart_4 = {
-    genericTest("test4", "", FILE_OPTION_SET, WITH_RESTART);
+    defaultTest("test4", "", FILE_OPTION_SET, WITH_RESTART);
   }
 
   @Test
   def noCompression_FileSet_StopRestart_WithLongWait_4B = {
-    genericTest("test4B", "", FILE_OPTION_SET, WITH_RESTART_AND_LONG_WAIT);
+    defaultTest("test4B", "", FILE_OPTION_SET, WITH_RESTART_AND_LONG_WAIT);
   }
 
   @Test
   def noCompression_FileSet_NoRestart_5 = {
-    genericTest("test5", "", FILE_OPTION_SET, NO_RESTART);
+    defaultTest("test5", "", FILE_OPTION_SET, NO_RESTART);
   }
 
   @Test
   def withCompression_FileSet_NoRestart_6 = {
-    genericTest("test6", ".gz", FILE_OPTION_SET, NO_RESTART);
+    defaultTest("test6", ".gz", FILE_OPTION_SET, NO_RESTART);
   }
 
   @Test
   def withMissingTargetDir = {
-    genericTest("missingTargetDir", "", FILE_OPTION_SET, NO_RESTART);
+    defaultTest("missingTargetDir", "", FILE_OPTION_SET, NO_RESTART);
+  }
+
+
+  @Test
+  def renaming = {
+
+    var fos: FileOutputStream = null
+    try {
+      val fileName = testId2FileName("failed_rename");
+      val file= new File(fileName)
+      file.getParentFile.mkdirs
+
+      fos = new FileOutputStream(fileName)
+      genericTest(zCheck)("failed_rename", "", FILE_OPTION_SET, NO_RESTART)
+
+    } finally {
+      StatusPrinter.print(context)
+      if(fos != null) fos.close;
+    }
   }
+
+
+
 }
\ No newline at end of file
diff --git a/logback-core/src/test/witness/rolling/tbr-failed_rename b/logback-core/src/test/witness/rolling/tbr-failed_rename
new file mode 100644
index 0000000..ff41e46
--- /dev/null
+++ b/logback-core/src/test/witness/rolling/tbr-failed_rename
@@ -0,0 +1,3 @@
+Hello---0
+Hello---1
+Hello---2
diff --git a/logback-site/src/site/pages/codes.html b/logback-site/src/site/pages/codes.html
index 9fa6bd7..a959b31 100644
--- a/logback-site/src/site/pages/codes.html
+++ b/logback-site/src/site/pages/codes.html
@@ -352,6 +352,24 @@
 
   <hr/>
 
+  <p><a name="renamingError" href="#renamingError">Failed to rename file [x]] to [y]</a>
+  </p>
+
+  <p>A log file cannot be renamed if there are handles referencing
+  that file. For example, when the file is read by another process
+  such as less, tail, etc. During application hot redeployment, the
+  old instance of the application will have open references to the log
+  file as long as the old instance is not gargabe collected.
+  </p>
+
+  <p>File renaming problems can be avoided altogether if the <span
+  class="option">file</span> option of
+  <code>RollingFileAppender</code> is left blank. 
+  </p>
+  
+  <hr/>
+
+
   <p>
     <a name="fwrp_parentFileName_not_set" href="#fwrp_parentFileName_not_set">
       The <span class="option">File</span> property must be set before

-----------------------------------------------------------------------

Summary of changes:
 .../logback/core/rolling/helper/RenameUtil.java    |    8 ++-
 .../logback/core/FileAppenderResilienceTest.java   |   10 +--
 .../qos/logback/core/rolling/RenameUtilTest.java   |   51 +----------------
 .../core/rolling/TimeBasedRolling2Test.scala       |   62 ++++++++++++++++----
 .../rolling/{tbr-test1.1 => tbr-failed_rename}     |    1 +
 logback-site/src/site/pages/codes.html             |   18 ++++++
 6 files changed, 79 insertions(+), 71 deletions(-)
 copy logback-core/src/test/witness/rolling/{tbr-test1.1 => tbr-failed_rename} (66%)


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list