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

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Tue Feb 23 14:16:58 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  87ceb3d44cefcf454b8635440bc75a37928961ee (commit)
      from  4097c6f76343e140bfc7ce11b73a95efceef0655 (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=87ceb3d44cefcf454b8635440bc75a37928961ee
http://github.com/ceki/logback/commit/87ceb3d44cefcf454b8635440bc75a37928961ee

commit 87ceb3d44cefcf454b8635440bc75a37928961ee
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Tue Feb 23 14:16:09 2010 +0100

    - measuring the differences between various fileAppender modes (imemdiateFlush, buffered io etc)

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 009490c..1a46b28 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,7 +41,7 @@ public class FileAppenderPerf {
     fa.setEncoder(patternLayout);
     fa.setFile(filename);
     fa.setAppend(false);
-    fa.setImmediateFlush(true);
+    fa.getEncoder().setImmediateFlush(true);
     fa.setBufferedIO(false);
     fa.setPrudent(safetyMode);
     fa.setContext(loggerContext);
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 afa7153..c2f4555 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,7 +66,7 @@ public class SafeModeFileAppender {
     fa.setEncoder(patternLayout);
     fa.setFile(filename);
     fa.setAppend(true);
-    fa.setImmediateFlush(true);
+    fa.getEncoder().setImmediateFlush(true);
     fa.setBufferedIO(false);
     fa.setPrudent(safetyMode);
     fa.setContext(loggerContext);
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 112f7d0..ee5f30d 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,7 +69,7 @@ public class SafeModeRollingFileAppender {
     rfa.setEncoder(patternLayout);
     
     rfa.setAppend(true);
-    rfa.setImmediateFlush(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 b392ba8..dbd0414 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,6 +18,7 @@ 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;
 
@@ -55,7 +56,6 @@ public class FileAppender<E> extends WriterAppender<E> {
 
   private boolean prudent = false;
 
-  
   /**
    * As in most cases, the default constructor does nothing.
    */
@@ -120,8 +120,9 @@ public class FileAppender<E> extends WriterAppender<E> {
           setAppend(true);
           addWarn("Setting \"Append\" property to true on account of \"Prudent\" mode");
         }
-        if (getImmediateFlush() == false) {
-          setImmediateFlush(true);
+        Encoder encoder = getEncoder();
+        if (encoder.getImmediateFlush() == false) {
+          encoder.setImmediateFlush(true);
           addWarn("Setting \"ImmediateFlush\" to true on account of \"Prudent\" mode");
         }
 
@@ -131,15 +132,6 @@ public class FileAppender<E> extends WriterAppender<E> {
         }
       }
 
-      // In case both bufferedIO and immediateFlush are set, the former
-      // takes priority because 'immediateFlush' is set to true by default.
-      // If the user explicitly set bufferedIO, then we should follow her
-      // directives.
-      if (bufferedIO) {
-        setImmediateFlush(false);
-        addInfo("Setting \"ImmediateFlush\" property to false on account of \"bufferedIO\" property");
-      }
-
       try {
         openFile(getFile());
       } catch (java.io.IOException e) {
@@ -189,12 +181,12 @@ public class FileAppender<E> extends WriterAppender<E> {
         }
       }
 
-      ResilientFileOutputStream resilientFos = new ResilientFileOutputStream(file, append);
-      
-      
-      //FileOutputStream fileOutputStream = new FileOutputStream(file_name,
-       //   append);
-      
+      ResilientFileOutputStream resilientFos = new ResilientFileOutputStream(
+          file, append);
+
+      // FileOutputStream fileOutputStream = new FileOutputStream(file_name,
+      // append);
+
       // Writer w = createWriter(fileOutputStream);
       // if (bufferedIO) {
       // w = new BufferedWriter(w, bufferSize);
@@ -245,7 +237,7 @@ public class FileAppender<E> extends WriterAppender<E> {
   final private void safeWrite(E event) throws IOException {
     ResilientFileOutputStream resilientFOS = (ResilientFileOutputStream) getOutputStream();
     FileChannel fileChannel = resilientFOS.getChannel();
-    if(fileChannel == null) {
+    if (fileChannel == null) {
       return;
     }
     FileLock fileLock = null;
diff --git a/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java b/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java
index 94a2172..e2de82c 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java
@@ -42,19 +42,6 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
    */
   protected Object lock = new Object();
 
-  /**
-   * Immediate flush means that the underlying writer or output stream will be
-   * flushed at the end of each append operation. Immediate flush is slower but
-   * ensures that each append request is actually written. If
-   * <code>immediateFlush</code> is set to <code>false</code>, then there is a
-   * good chance that the last few logs events are not actually written to
-   * persistent media if and when the application crashes.
-   * 
-   * <p>
-   * The <code>immediateFlush</code> variable is set to <code>true</code> by
-   * default.
-   */
-  private boolean immediateFlush = true;
 
   /**
    * This is the {@link OutputStream outputStream} where output will be written.
@@ -67,22 +54,6 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
   public WriterAppender() {
   }
 
-  /**
-   * If the <b>ImmediateFlush</b> option is set to <code>true</code>, the
-   * appender will flush at the end of each write. This is the default behavior.
-   * If the option is set to <code>false</code>, then the underlying stream can
-   * defer writing to physical medium to a later time.
-   * <p>
-   * Avoiding the flush operation at the end of each append results in a
-   * performance gain of 10 to 20 percent. However, there is safety tradeoff
-   * involved in skipping flushing. Indeed, when flushing is skipped, then it is
-   * likely that the last few log events will not be recorded on disk when the
-   * application exits. This is a high price to pay even for a 20% performance
-   * gain.
-   */
-  public void setImmediateFlush(boolean value) {
-    immediateFlush = value;
-  }
 
   /**
    * The underlying output stream used by this appender.
@@ -94,13 +65,6 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
   }
 
   /**
-   * Returns value of the <b>ImmediateFlush</b> option.
-   */
-  public boolean getImmediateFlush() {
-    return immediateFlush;
-  }
-
-  /**
    * Checks that requires parameters are set and if everything is in order,
    * activates this appender.
    */
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 18219be..9a989a3 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,5 +24,7 @@ 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 aaab297..ebbec74 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,8 @@ 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;
   }
@@ -26,4 +27,16 @@ 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/html/LayoutWrappingEncoder.java b/logback-core/src/main/java/ch/qos/logback/core/html/LayoutWrappingEncoder.java
index caab0ce..ed91af0 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/html/LayoutWrappingEncoder.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/html/LayoutWrappingEncoder.java
@@ -21,6 +21,7 @@ public class LayoutWrappingEncoder<E> extends EncoderBase<E> {
    */
   private Charset charset;
 
+  
   public Layout<E> getLayout() {
     return layout;
   }
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 b0fcdcf..21ffe73 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
@@ -106,12 +106,12 @@ public class FileAppenderTest extends AbstractAppenderTest<Object> {
     appender.setContext(context);
 
     appender.setAppend(false);
-    appender.setImmediateFlush(false);
+    appender.getEncoder().setImmediateFlush(false);
     appender.setBufferedIO(true);
     appender.setPrudent(true);
     appender.start();
 
-    assertTrue(appender.getImmediateFlush());
+    assertTrue(appender.getEncoder().getImmediateFlush());
     assertTrue(appender.isAppend());
     assertFalse(appender.isBufferedIO());
 
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/util/House.java b/logback-core/src/test/java/ch/qos/logback/core/joran/util/House.java
index c2270b0..ef27c4f 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/util/House.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/util/House.java
@@ -12,6 +12,7 @@ import ch.qos.logback.core.util.FileSize;
 public class House {
   Door mainDoor;
   int count;
+  Double temperature;
   boolean open;
   String name;
   String camelCase;
@@ -20,7 +21,8 @@ public class House {
   FileSize fs;
   HouseColor houseColor;
   FilterReply reply;
-
+  
+  
   Charset charset;
 
   List<String> adjectiveList = new ArrayList<String>();
@@ -43,6 +45,15 @@ public class House {
     this.count = c;
   }
 
+  
+  public Double getTemperature() {
+    return temperature;
+  }
+
+  public void setTemperature(Double temperature) {
+    this.temperature = temperature;
+  }
+
   public Door getDoor() {
     return mainDoor;
   }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/util/PackageTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/util/PackageTest.java
index feb3d0a..f808043 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/util/PackageTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/util/PackageTest.java
@@ -18,6 +18,6 @@ import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
 
 @RunWith(Suite.class)
- at SuiteClasses( { StringToObjectConverterTest.class, PropertySetterTest.class })
+ at SuiteClasses( { PropertySetterTest.class })
 public class PackageTest {
 }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/util/PropertySetterTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/util/PropertySetterTest.java
index 0ac9396..8d93421 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/util/PropertySetterTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/util/PropertySetterTest.java
@@ -90,10 +90,13 @@ public class PropertySetterTest {
       House house = new House();
       PropertySetter setter = new PropertySetter(house);
       setter.setProperty("count", "10");
+      setter.setProperty("temperature", "33.1");
+      
       setter.setProperty("name", "jack");
       setter.setProperty("open", "true");
 
       assertEquals(10, house.getCount());
+      assertEquals(33.1d, (double) house.getTemperature(), 0.01);
       assertEquals("jack", house.getName());
       assertTrue(house.isOpen());
     }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/util/StringToObjectConverterTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/util/StringToObjectConverterTest.java
deleted file mode 100644
index 48886ea..0000000
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/util/StringToObjectConverterTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package ch.qos.logback.core.joran.util;
-
-import org.junit.Test;
-
-public class StringToObjectConverterTest {
-
-  
-  
-  @Test 
-  public void doubleTest() {
-    fail("s");
-  }
-}
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 e4cbc01..49fa223 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,7 +81,7 @@ 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.setImmediateFlush(false);
+    rfa.getEncoder().setImmediateFlush(false);
     rfa.setBufferedIO(true);
     rfa.setPrudent(true);
 
@@ -92,7 +92,7 @@ public class RollingFileAppenderTest extends AbstractAppenderTest<Object> {
 
     rfa.start();
 
-    assertTrue(rfa.getImmediateFlush());
+    assertTrue(rfa.getEncoder().getImmediateFlush());
     assertTrue(rfa.isAppend());
     assertFalse(rfa.isBufferedIO());
     assertNull(rfa.rawFileProperty());
@@ -103,7 +103,7 @@ public class RollingFileAppenderTest extends AbstractAppenderTest<Object> {
   public void testPrudentModeLogicalImplicationsOnCompression() {
     rfa.setContext(context);
     rfa.setAppend(false);
-    rfa.setImmediateFlush(false);
+    rfa.getEncoder().setImmediateFlush(false);
     rfa.setBufferedIO(true);
     rfa.setPrudent(true);
 
diff --git a/logback-examples/src/main/java/chapter4/ExitWoes1.java b/logback-examples/src/main/java/chapter4/ExitWoes1.java
index b14a36e..a1ca13c 100644
--- a/logback-examples/src/main/java/chapter4/ExitWoes1.java
+++ b/logback-examples/src/main/java/chapter4/ExitWoes1.java
@@ -35,7 +35,7 @@ public class ExitWoes1 {
 
     OutputStream os = new FileOutputStream("exitWoes1.log");
     writerAppender.setOutputStream(os);
-    writerAppender.setImmediateFlush(false);
+    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 d95631a..57733bb 100644
--- a/logback-examples/src/main/java/chapter4/ExitWoes2.java
+++ b/logback-examples/src/main/java/chapter4/ExitWoes2.java
@@ -36,7 +36,7 @@ public class ExitWoes2 {
 
     OutputStream os = new FileOutputStream("exitWoes2.log");
     writerAppender.setOutputStream(os);
-    writerAppender.setImmediateFlush(false);
+    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 fb989ce..128d75f 100644
--- a/logback-examples/src/main/java/chapter4/IO.java
+++ b/logback-examples/src/main/java/chapter4/IO.java
@@ -58,7 +58,7 @@ public class IO extends Thread {
 
     fa.setFile(getName() + ".log");
     fa.setAppend(false);
-    fa.setImmediateFlush(immediateFlush);
+    fa.getEncoder().setImmediateFlush(immediateFlush);
     fa.setBufferedIO(buffered);
     fa.setContext(context);
     fa.start();
@@ -170,6 +170,9 @@ class Counter extends Thread {
     long before = System.nanoTime();
 
     while (!interrupted) {
+      if(counter % 1000 == 0) {
+          Thread.yield();
+      }
       counter += 1.0;
     }
 
diff --git a/logback-site/src/site/pages/manual/migrationFromLog4j.html b/logback-site/src/site/pages/manual/migrationFromLog4j.html
index a0b7059..ed7cd04 100644
--- a/logback-site/src/site/pages/manual/migrationFromLog4j.html
+++ b/logback-site/src/site/pages/manual/migrationFromLog4j.html
@@ -41,7 +41,10 @@
     <code>org.apache.log4j</code> package, can be automatically
     migrated to use SLF4J via the <a
     href="http://www.slf4j.org/migrator.html">SLF4J migrator
-    tool</a>. 
+    tool</a>. To migrate <em>log4j.property</em> files into its
+    logback equivalent, you can use the <a
+    href="http://logback.qos.ch/translator/">log4j.properties
+    translator</a>.
     </p>
 
     <p>From a broader perspective, log4j and logback-classic are

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

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     |   30 ++++++----------
 .../java/ch/qos/logback/core/WriterAppender.java   |   36 --------------------
 .../java/ch/qos/logback/core/encoder/Encoder.java  |    4 ++-
 .../ch/qos/logback/core/encoder/EncoderBase.java   |   15 ++++++++-
 .../logback/core/html/LayoutWrappingEncoder.java   |    1 +
 .../logback/core/appender/FileAppenderTest.java    |    4 +-
 .../java/ch/qos/logback/core/joran/util/House.java |   13 ++++++-
 .../qos/logback/core/joran/util/PackageTest.java   |    2 +-
 .../core/joran/util/PropertySetterTest.java        |    3 ++
 .../joran/util/StringToObjectConverterTest.java    |   13 -------
 .../core/rolling/RollingFileAppenderTest.java      |    6 ++--
 .../src/main/java/chapter4/ExitWoes1.java          |    2 +-
 .../src/main/java/chapter4/ExitWoes2.java          |    2 +-
 logback-examples/src/main/java/chapter4/IO.java    |    5 ++-
 .../src/site/pages/manual/migrationFromLog4j.html  |    5 ++-
 18 files changed, 63 insertions(+), 84 deletions(-)
 delete mode 100644 logback-core/src/test/java/ch/qos/logback/core/joran/util/StringToObjectConverterTest.java


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


More information about the logback-dev mailing list