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

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Sun Feb 21 22:47:55 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  4316ce3c37be6fd8fbad4e9a0645bedb9a487b8e (commit)
      from  ade00738d1df9cf6d56d3fb98ca28c5977e688d6 (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=4316ce3c37be6fd8fbad4e9a0645bedb9a487b8e
http://github.com/ceki/logback/commit/4316ce3c37be6fd8fbad4e9a0645bedb9a487b8e

commit 4316ce3c37be6fd8fbad4e9a0645bedb9a487b8e
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Sun Feb 21 22:44:54 2010 +0100

    - Initial attempt at fixing LBCORE-109

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 4e4c6aa..72be15c 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
@@ -14,11 +14,11 @@
 package ch.qos.logback.core;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
 
+import ch.qos.logback.core.recovery.ResilientFileOutputStream;
 import ch.qos.logback.core.util.FileUtil;
 
 /**
@@ -55,8 +55,7 @@ public class FileAppender<E> extends WriterAppender<E> {
 
   private boolean prudent = false;
 
-  private FileChannel fileChannel = null;
-
+  
   /**
    * As in most cases, the default constructor does nothing.
    */
@@ -190,16 +189,17 @@ public class FileAppender<E> extends WriterAppender<E> {
         }
       }
 
-      FileOutputStream fileOutputStream = new FileOutputStream(file_name,
-          append);
-      if (prudent) {
-        fileChannel = fileOutputStream.getChannel();
-      }
+      ResilientFileOutputStream resilientFos = new ResilientFileOutputStream(file, append);
+      
+      
+      //FileOutputStream fileOutputStream = new FileOutputStream(file_name,
+       //   append);
+      
       // Writer w = createWriter(fileOutputStream);
       // if (bufferedIO) {
       // w = new BufferedWriter(w, bufferSize);
       // }
-      setWriter(fileOutputStream);
+      setWriter(resilientFos);
     }
   }
 
@@ -243,6 +243,11 @@ 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) {
+      return;
+    }
     FileLock fileLock = null;
     try {
       fileLock = fileChannel.lock();
@@ -261,7 +266,7 @@ public class FileAppender<E> extends WriterAppender<E> {
 
   @Override
   protected void writeOut(E event) throws IOException {
-    if (prudent && fileChannel != null) {
+    if (prudent) {
       safeWrite(event);
     } else {
       super.writeOut(event);
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 df991d7..e0410ed 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
@@ -86,6 +86,10 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
     immediateFlush = value;
   }
 
+  protected OutputStream getOutputStream() {
+    return outputStream;
+  }
+  
   /**
    * Returns value of the <b>ImmediateFlush</b> option.
    */
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
new file mode 100644
index 0000000..eefdbf8
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/recovery/RecoveryCoordinator.java
@@ -0,0 +1,30 @@
+/**
+ * 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;
+
+public class RecoveryCoordinator {
+
+  
+  long next = System.currentTimeMillis()+100;
+  
+  public boolean isTooSoon() {
+    long now =System.currentTimeMillis();
+    if(now > next) {
+      next = now + 100;
+      return false;
+    } else {
+      return true;
+    }
+  }
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/recovery/ResilientFileOutputStream.java b/logback-core/src/main/java/ch/qos/logback/core/recovery/ResilientFileOutputStream.java
new file mode 100644
index 0000000..b0b7980
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/recovery/ResilientFileOutputStream.java
@@ -0,0 +1,96 @@
+/**
+ * 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 java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.channels.FileChannel;
+
+public class ResilientFileOutputStream extends OutputStream {
+
+  RecoveryCoordinator recoveryCoordinator;
+  // private FileChannel fileChannel = null;
+  boolean bufferedIO;
+  int bufferSize;
+
+  FileOutputStream fos;
+  File file;
+
+  public ResilientFileOutputStream(File file, boolean append) throws FileNotFoundException {
+    this.file = file;
+    fos = new FileOutputStream(file, append);
+  }
+
+  public FileChannel getChannel() {
+    if (fos == null) {
+      return null;
+    }
+    return fos.getChannel();
+  }
+
+  public void write(byte b[], int off, int len) throws IOException {
+    // existence of recoveryCoordinator indicates failed state
+    if (recoveryCoordinator != null) {
+      if (!recoveryCoordinator.isTooSoon()) {
+        performRecoveryAttempt();
+      }
+      // we return regardless of the success of the recovery attempt
+      return;
+    }
+
+    try {
+      fos.write(b, off, len);
+      postSuccessfulWrite();
+    } catch (IOException e) {
+      recoveryCoordinator = new RecoveryCoordinator();
+    }
+  }
+
+  private void postSuccessfulWrite() {
+    recoveryCoordinator = null;
+  }
+
+  @Override
+  public void close() throws IOException {
+    if(fos != null) {
+      fos.close();
+    }
+  }
+  
+  @Override
+  public void write(int b) throws IOException {
+    // existence of recoveryCoordinator indicates failed state
+    if (recoveryCoordinator != null) {
+      if (!recoveryCoordinator.isTooSoon()) {
+        performRecoveryAttempt();
+      }
+      // we return regardless of the success of the recovery attempt
+      return;
+    }
+    try {
+      fos.write(b);
+      postSuccessfulWrite();
+    } catch (IOException e) {
+      recoveryCoordinator = new RecoveryCoordinator();
+    }
+  }
+
+  void performRecoveryAttempt() throws FileNotFoundException {
+    fos = new FileOutputStream(file);
+  }
+
+}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/encoder/ObjectEncodeDecodeTest.java b/logback-core/src/test/java/ch/qos/logback/core/encoder/ObjectEncodeDecodeTest.java
index 2f43dae..42ac3c7 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/encoder/ObjectEncodeDecodeTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/encoder/ObjectEncodeDecodeTest.java
@@ -1,10 +1,9 @@
 package ch.qos.logback.core.encoder;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;

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

Summary of changes:
 .../java/ch/qos/logback/core/FileAppender.java     |   25 +++--
 .../java/ch/qos/logback/core/WriterAppender.java   |    4 +
 .../logback/core/recovery/RecoveryCoordinator.java |   30 ++++++
 .../core/recovery/ResilientFileOutputStream.java   |   96 ++++++++++++++++++++
 .../core/encoder/ObjectEncodeDecodeTest.java       |    3 +-
 5 files changed, 146 insertions(+), 12 deletions(-)
 create mode 100644 logback-core/src/main/java/ch/qos/logback/core/recovery/RecoveryCoordinator.java
 create mode 100644 logback-core/src/main/java/ch/qos/logback/core/recovery/ResilientFileOutputStream.java


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


More information about the logback-dev mailing list