[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, encoder, updated. v0.9.18-44-gadae893

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Tue Feb 23 16:07:54 CET 2010


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, encoder has been updated
       via  adae89397fcecee04c69f241db87427cc218d254 (commit)
      from  87ceb3d44cefcf454b8635440bc75a37928961ee (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=adae89397fcecee04c69f241db87427cc218d254
http://github.com/ceki/logback/commit/adae89397fcecee04c69f241db87427cc218d254

commit adae89397fcecee04c69f241db87427cc218d254
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Tue Feb 23 16:03:31 2010 +0100

    - Given the IO performance is pretty good, in order to simplify usage
      removed the immediateFlush, BufferedIO properties from FileAppender
    
      Only immediateFlush can make a significant difference in presense of
      other IO activity on a mechanical HD.

diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/FileAppenderPerf.java b/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/FileAppenderPerf.java
index 1a46b28..ddddea0 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/FileAppenderPerf.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/FileAppenderPerf.java
@@ -41,8 +41,6 @@ public class FileAppenderPerf {
     fa.setEncoder(patternLayout);
     fa.setFile(filename);
     fa.setAppend(false);
-    fa.getEncoder().setImmediateFlush(true);
-    fa.setBufferedIO(false);
     fa.setPrudent(safetyMode);
     fa.setContext(loggerContext);
     fa.start();
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/SafeModeFileAppender.java b/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/SafeModeFileAppender.java
index c2f4555..ea2c2e9 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/SafeModeFileAppender.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/SafeModeFileAppender.java
@@ -66,8 +66,6 @@ public class SafeModeFileAppender {
     fa.setEncoder(patternLayout);
     fa.setFile(filename);
     fa.setAppend(true);
-    fa.getEncoder().setImmediateFlush(true);
-    fa.setBufferedIO(false);
     fa.setPrudent(safetyMode);
     fa.setContext(loggerContext);
     fa.start();
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/SafeModeRollingFileAppender.java b/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/SafeModeRollingFileAppender.java
index ee5f30d..96b0c41 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/SafeModeRollingFileAppender.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/multiJVM/SafeModeRollingFileAppender.java
@@ -69,8 +69,6 @@ public class SafeModeRollingFileAppender {
     rfa.setEncoder(patternLayout);
     
     rfa.setAppend(true);
-    rfa.getEncoder().setImmediateFlush(true);
-    rfa.setBufferedIO(false);
     rfa.setPrudent(safetyMode);
     rfa.setContext(loggerContext);
 
diff --git a/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java b/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java
index dbd0414..418537b 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java
@@ -18,7 +18,6 @@ import java.io.IOException;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
 
-import ch.qos.logback.core.encoder.Encoder;
 import ch.qos.logback.core.recovery.ResilientFileOutputStream;
 import ch.qos.logback.core.util.FileUtil;
 
@@ -45,11 +44,6 @@ public class FileAppender<E> extends WriterAppender<E> {
   protected String fileName = null;
 
   /**
-   * Do we do bufferedIO?
-   */
-  protected boolean bufferedIO = false;
-
-  /**
    * The size of the IO buffer. Default is 8K.
    */
   protected int bufferSize = 8 * 1024;
@@ -120,16 +114,6 @@ public class FileAppender<E> extends WriterAppender<E> {
           setAppend(true);
           addWarn("Setting \"Append\" property to true on account of \"Prudent\" mode");
         }
-        Encoder encoder = getEncoder();
-        if (encoder.getImmediateFlush() == false) {
-          encoder.setImmediateFlush(true);
-          addWarn("Setting \"ImmediateFlush\" to true on account of \"Prudent\" mode");
-        }
-
-        if (bufferedIO == true) {
-          setBufferedIO(false);
-          addWarn("Setting \"BufferedIO\" property to false on account of \"Prudent\" mode");
-        }
       }
 
       try {
@@ -184,24 +168,11 @@ public class FileAppender<E> extends WriterAppender<E> {
       ResilientFileOutputStream resilientFos = new ResilientFileOutputStream(
           file, append);
 
-      // FileOutputStream fileOutputStream = new FileOutputStream(file_name,
-      // append);
-
-      // Writer w = createWriter(fileOutputStream);
-      // if (bufferedIO) {
-      // w = new BufferedWriter(w, bufferSize);
-      // }
       setOutputStream(resilientFos);
     }
   }
 
-  public boolean isBufferedIO() {
-    return bufferedIO;
-  }
 
-  public void setBufferedIO(boolean bufferedIO) {
-    this.bufferedIO = bufferedIO;
-  }
 
   public int getBufferSize() {
     return bufferSize;
diff --git a/logback-core/src/main/java/ch/qos/logback/core/encoder/Encoder.java b/logback-core/src/main/java/ch/qos/logback/core/encoder/Encoder.java
index 9a989a3..821db3d 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/encoder/Encoder.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/encoder/Encoder.java
@@ -24,7 +24,4 @@ public interface Encoder<E> extends ContextAware, LifeCycle {
   void doEncode(E event) throws IOException;
   void init(OutputStream os) throws IOException;
   void close() throws IOException;
- 
-  public boolean getImmediateFlush();
-  public void setImmediateFlush(boolean value);
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/encoder/EncoderBase.java b/logback-core/src/main/java/ch/qos/logback/core/encoder/EncoderBase.java
index ebbec74..d5e93d7 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/encoder/EncoderBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/encoder/EncoderBase.java
@@ -10,7 +10,6 @@ abstract public class EncoderBase<E> extends ContextAwareBase implements Encoder
   protected boolean started;
 
   protected OutputStream outputStream;
-  private boolean immediateFlush = true;
   
   public void init(OutputStream os) throws IOException {
     this.outputStream = os;
@@ -27,16 +26,5 @@ abstract public class EncoderBase<E> extends ContextAwareBase implements Encoder
   public void stop() {
     started = false;
   }
-  
-  
-  /**
-   * Returns value of the <b>ImmediateFlush</b> option.
-   */
-  public boolean getImmediateFlush() {
-    return immediateFlush;
-  }
+}  
 
-  public void setImmediateFlush(boolean value) {
-    immediateFlush = value;
-  }
-}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/recovery/RecoveryCoordinator.java b/logback-core/src/main/java/ch/qos/logback/core/recovery/RecoveryCoordinator.java
index eefdbf8..7f4b99f 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/recovery/RecoveryCoordinator.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/recovery/RecoveryCoordinator.java
@@ -15,16 +15,41 @@ package ch.qos.logback.core.recovery;
 
 public class RecoveryCoordinator {
 
+  static long BACKOFF_COEFFICIENT_MIN = 100;
+  static long BACKOFF_COEFFICIENT_MAX = 409600;  // BACKOFF_COEFFICIENT_MIN * 4^6
   
-  long next = System.currentTimeMillis()+100;
+  private long backOffCoefficient = BACKOFF_COEFFICIENT_MIN;
+  
+  private static long UNSET = -1;
+  private long currentTime = UNSET;
+  long next = System.currentTimeMillis()+getBackoffCoefficient();
   
   public boolean isTooSoon() {
-    long now =System.currentTimeMillis();
+    long now = getCurrentTime();
     if(now > next) {
-      next = now + 100;
+      next = now + getBackoffCoefficient();
       return false;
     } else {
       return true;
     }
   }
+  
+  void setCurrentTime(long forcedTime) {
+    currentTime = forcedTime;
+  }
+  
+  private long getCurrentTime() {
+    if(currentTime != UNSET) {
+      return currentTime;
+    }
+    return System.currentTimeMillis();
+  }
+  
+  private long getBackoffCoefficient() {
+    long currentCoeff = backOffCoefficient;
+    if(backOffCoefficient < BACKOFF_COEFFICIENT_MAX) {
+      backOffCoefficient*=4;
+    }
+    return currentCoeff;
+  }
 }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/AllCoreTest.java b/logback-core/src/test/java/ch/qos/logback/core/AllCoreTest.java
index d4eca59..fc3618e 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/AllCoreTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/AllCoreTest.java
@@ -28,7 +28,8 @@ import org.junit.runners.Suite.SuiteClasses;
   ch.qos.logback.core.spi.PackageTest.class,
   ch.qos.logback.core.rolling.PackageTest.class,
   ch.qos.logback.core.sift.PackageTest.class, 
-  ch.qos.logback.core.encoder.PackageTest.class})
+  ch.qos.logback.core.encoder.PackageTest.class,
+  ch.qos.logback.core.recovery.PackageTest.class})
 public class AllCoreTest {
 
 }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java b/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java
index 21ffe73..0c3f5d1 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java
@@ -33,6 +33,7 @@ import ch.qos.logback.core.status.Status;
 import ch.qos.logback.core.status.StatusManager;
 import ch.qos.logback.core.util.CoreTestConstants;
 import ch.qos.logback.core.util.FileUtil;
+import ch.qos.logback.core.util.StatusPrinter;
 
 public class FileAppenderTest extends AbstractAppenderTest<Object> {
 
@@ -106,20 +107,17 @@ public class FileAppenderTest extends AbstractAppenderTest<Object> {
     appender.setContext(context);
 
     appender.setAppend(false);
-    appender.getEncoder().setImmediateFlush(false);
-    appender.setBufferedIO(true);
     appender.setPrudent(true);
     appender.start();
 
-    assertTrue(appender.getEncoder().getImmediateFlush());
     assertTrue(appender.isAppend());
-    assertFalse(appender.isBufferedIO());
 
     StatusManager sm = context.getStatusManager();
+    StatusPrinter.print(context);
     assertEquals(Status.WARN, sm.getLevel());
     List<Status> statusList = sm.getCopyOfStatusList();
-    assertTrue("Expecting status list size to be larger than 3, but was "
-        + statusList.size(), statusList.size() > 3);
+    assertTrue("Expecting status list size to be 2 or larger, but was "
+        + statusList.size(), statusList.size() >= 2);
     String msg1 = statusList.get(1).getMessage();
 
     assertTrue("Got message [" + msg1 + "]", msg1
diff --git a/logback-core/src/main/java/ch/qos/logback/core/encoder/Encoder.java b/logback-core/src/test/java/ch/qos/logback/core/recovery/PackageTest.java
similarity index 50%
copy from logback-core/src/main/java/ch/qos/logback/core/encoder/Encoder.java
copy to logback-core/src/test/java/ch/qos/logback/core/recovery/PackageTest.java
index 9a989a3..8cebd38 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/encoder/Encoder.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/recovery/PackageTest.java
@@ -11,20 +11,13 @@
  * under the terms of the GNU Lesser General Public License version 2.1
  * as published by the Free Software Foundation.
  */
-package ch.qos.logback.core.encoder;
+package ch.qos.logback.core.recovery;
 
-import java.io.IOException;
-import java.io.OutputStream;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
 
-import ch.qos.logback.core.spi.ContextAware;
-import ch.qos.logback.core.spi.LifeCycle;
-
-public interface Encoder<E> extends ContextAware, LifeCycle {
-  
-  void doEncode(E event) throws IOException;
-  void init(OutputStream os) throws IOException;
-  void close() throws IOException;
- 
-  public boolean getImmediateFlush();
-  public void setImmediateFlush(boolean value);
-}
+ at RunWith(Suite.class)
+ at SuiteClasses({RecoveryCoordinatorTest.class})
+public class PackageTest  {
+}
\ No newline at end of file
diff --git a/logback-core/src/test/java/ch/qos/logback/core/recovery/RecoveryCoordinatorTest.java b/logback-core/src/test/java/ch/qos/logback/core/recovery/RecoveryCoordinatorTest.java
new file mode 100644
index 0000000..1d30e5c
--- /dev/null
+++ b/logback-core/src/test/java/ch/qos/logback/core/recovery/RecoveryCoordinatorTest.java
@@ -0,0 +1,57 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2010, QOS.ch. All rights reserved.
+ * 
+ * This program and the accompanying materials are dual-licensed under either
+ * the terms of the Eclipse Public License v1.0 as published by the Eclipse
+ * Foundation
+ * 
+ * or (per the licensee's choosing)
+ * 
+ * under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ */
+package ch.qos.logback.core.recovery;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class RecoveryCoordinatorTest {
+
+  RecoveryCoordinator rc = new RecoveryCoordinator();
+  long now = System.currentTimeMillis();
+
+  @Test
+  public void actualTime() throws InterruptedException {
+    assertTrue(rc.isTooSoon());
+    Thread.sleep(RecoveryCoordinator.BACKOFF_COEFFICIENT_MIN+20);
+    assertFalse(rc.isTooSoon());
+  }
+  
+  @Test
+  public void smoke() {
+    assertTrue(rc.isTooSoon());
+    rc.setCurrentTime(now+RecoveryCoordinator.BACKOFF_COEFFICIENT_MIN+1);
+    assertFalse(rc.isTooSoon());
+  }
+  
+  @Test
+  public void longTermFailure() {
+    long offset = RecoveryCoordinator.BACKOFF_COEFFICIENT_MIN;
+    int tooSoonCount = 0;
+    for(int i = 0; i < 16; i++) {
+      rc.setCurrentTime(now+offset);
+     
+      if(rc.isTooSoon()) {
+        //System.out.println("is     too soon at "+(offset));
+        tooSoonCount++;
+      } else {
+        //System.out.println("is NOT too soon at "+(offset));
+    }
+      offset *= 2;
+    }
+    assertEquals(7, tooSoonCount);
+    
+  }
+}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java
index 49fa223..659d4a4 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java
@@ -81,8 +81,6 @@ public class RollingFileAppenderTest extends AbstractAppenderTest<Object> {
     // prudent mode will force "file" property to be null
     rfa.setFile("some non null value");
     rfa.setAppend(false);
-    rfa.getEncoder().setImmediateFlush(false);
-    rfa.setBufferedIO(true);
     rfa.setPrudent(true);
 
     tbrp
@@ -92,9 +90,7 @@ public class RollingFileAppenderTest extends AbstractAppenderTest<Object> {
 
     rfa.start();
 
-    assertTrue(rfa.getEncoder().getImmediateFlush());
     assertTrue(rfa.isAppend());
-    assertFalse(rfa.isBufferedIO());
     assertNull(rfa.rawFileProperty());
     assertTrue(rfa.isStarted());
   }
@@ -103,8 +99,6 @@ public class RollingFileAppenderTest extends AbstractAppenderTest<Object> {
   public void testPrudentModeLogicalImplicationsOnCompression() {
     rfa.setContext(context);
     rfa.setAppend(false);
-    rfa.getEncoder().setImmediateFlush(false);
-    rfa.setBufferedIO(true);
     rfa.setPrudent(true);
 
     tbrp.setFileNamePattern("toto-%d.log.zip");
diff --git a/logback-examples/src/main/java/chapter4/ExitWoes1.java b/logback-examples/src/main/java/chapter4/ExitWoes1.java
index a1ca13c..e99234c 100644
--- a/logback-examples/src/main/java/chapter4/ExitWoes1.java
+++ b/logback-examples/src/main/java/chapter4/ExitWoes1.java
@@ -35,7 +35,6 @@ public class ExitWoes1 {
 
     OutputStream os = new FileOutputStream("exitWoes1.log");
     writerAppender.setOutputStream(os);
-    writerAppender.getEncoder().setImmediateFlush(false);
     writerAppender.start();
     Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
     root.addAppender(writerAppender);
diff --git a/logback-examples/src/main/java/chapter4/ExitWoes2.java b/logback-examples/src/main/java/chapter4/ExitWoes2.java
index 57733bb..121e89a 100644
--- a/logback-examples/src/main/java/chapter4/ExitWoes2.java
+++ b/logback-examples/src/main/java/chapter4/ExitWoes2.java
@@ -36,7 +36,6 @@ public class ExitWoes2 {
 
     OutputStream os = new FileOutputStream("exitWoes2.log");
     writerAppender.setOutputStream(os);
-    writerAppender.getEncoder().setImmediateFlush(false);
     writerAppender.start();
     Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
     root.addAppender(writerAppender);
diff --git a/logback-examples/src/main/java/chapter4/IO.java b/logback-examples/src/main/java/chapter4/IO.java
index 128d75f..3618774 100644
--- a/logback-examples/src/main/java/chapter4/IO.java
+++ b/logback-examples/src/main/java/chapter4/IO.java
@@ -58,8 +58,6 @@ public class IO extends Thread {
 
     fa.setFile(getName() + ".log");
     fa.setAppend(false);
-    fa.getEncoder().setImmediateFlush(immediateFlush);
-    fa.setBufferedIO(buffered);
     fa.setContext(context);
     fa.start();
     

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

Summary of changes:
 .../logback/classic/multiJVM/FileAppenderPerf.java |    2 -
 .../classic/multiJVM/SafeModeFileAppender.java     |    2 -
 .../multiJVM/SafeModeRollingFileAppender.java      |    2 -
 .../java/ch/qos/logback/core/FileAppender.java     |   29 ----------
 .../java/ch/qos/logback/core/encoder/Encoder.java  |    3 -
 .../ch/qos/logback/core/encoder/EncoderBase.java   |   14 +-----
 .../logback/core/recovery/RecoveryCoordinator.java |   31 ++++++++++-
 .../test/java/ch/qos/logback/core/AllCoreTest.java |    3 +-
 .../logback/core/appender/FileAppenderTest.java    |   10 ++--
 .../ch/qos/logback/core/recovery}/PackageTest.java |    5 +-
 .../core/recovery/RecoveryCoordinatorTest.java     |   57 ++++++++++++++++++++
 .../core/rolling/RollingFileAppenderTest.java      |    6 --
 .../src/main/java/chapter4/ExitWoes1.java          |    1 -
 .../src/main/java/chapter4/ExitWoes2.java          |    1 -
 logback-examples/src/main/java/chapter4/IO.java    |    2 -
 15 files changed, 94 insertions(+), 74 deletions(-)
 copy {logback-access/src/test/java/ch/qos/logback/access/sift => logback-core/src/test/java/ch/qos/logback/core/recovery}/PackageTest.java (88%)
 create mode 100644 logback-core/src/test/java/ch/qos/logback/core/recovery/RecoveryCoordinatorTest.java


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


More information about the logback-dev mailing list