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

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Thu Feb 18 20:22:10 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  e4da8a824934b61ea4d8c885d8f65a8ec3b1e85e (commit)
      from  e5b5e16ad145327257be746e23153ac14e7bccad (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=e4da8a824934b61ea4d8c885d8f65a8ec3b1e85e
http://github.com/ceki/logback/commit/e4da8a824934b61ea4d8c885d8f65a8ec3b1e85e

commit e4da8a824934b61ea4d8c885d8f65a8ec3b1e85e
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Thu Feb 18 20:19:33 2010 +0100

    - all logback-core tests pass. Ongoing work.

diff --git a/logback-access/src/main/java/ch/qos/logback/access/PatternEncoder.java b/logback-access/src/main/java/ch/qos/logback/access/PatternLayoutEncoder.java
similarity index 62%
rename from logback-access/src/main/java/ch/qos/logback/access/PatternEncoder.java
rename to logback-access/src/main/java/ch/qos/logback/access/PatternLayoutEncoder.java
index f27a561..7fbdc30 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/PatternEncoder.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/PatternLayoutEncoder.java
@@ -1,10 +1,10 @@
 package ch.qos.logback.access;
 
 import ch.qos.logback.access.spi.AccessEvent;
-import ch.qos.logback.core.pattern.PatternEncoderBase;
+import ch.qos.logback.core.pattern.PatternLayoutEncoderBase;
 
 
-public class PatternEncoder extends PatternEncoderBase<AccessEvent> {
+public class PatternLayoutEncoder extends PatternLayoutEncoderBase<AccessEvent> {
 
   public void start() {
     layout = new PatternLayout();
diff --git a/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyFixture.java b/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyFixture.java
index e667fad..87fb172 100644
--- a/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyFixture.java
+++ b/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyFixture.java
@@ -26,7 +26,7 @@ import org.mortbay.jetty.Request;
 import org.mortbay.jetty.handler.AbstractHandler;
 import org.mortbay.util.ByteArrayISO8859Writer;
 
-import ch.qos.logback.access.PatternEncoder;
+import ch.qos.logback.access.PatternLayoutEncoder;
 import ch.qos.logback.access.spi.AccessEvent;
 import ch.qos.logback.access.testUtil.NotifyingListAppender;
 import ch.qos.logback.core.ConsoleAppender;
@@ -59,7 +59,7 @@ public class JettyFixture extends JettyFixtureBase {
     ConsoleAppender<AccessEvent> console = new ConsoleAppender<AccessEvent>();
     console.setContext(requestLogImpl);
     console.setName("console");
-    PatternEncoder layout = new PatternEncoder();
+    PatternLayoutEncoder layout = new PatternLayoutEncoder();
     layout.setContext(requestLogImpl);
     layout.setPattern("%date %server %clientHost");
     console.setEncoder(layout);
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/BasicConfigurator.java b/logback-classic/src/main/java/ch/qos/logback/classic/BasicConfigurator.java
index 5bb119f..b6e0eca 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/BasicConfigurator.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/BasicConfigurator.java
@@ -15,7 +15,7 @@ package ch.qos.logback.classic;
 
 import org.slf4j.LoggerFactory;
 
-import ch.qos.logback.classic.encoder.PatternEncoder;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.ConsoleAppender;
 import ch.qos.logback.core.status.InfoStatus;
@@ -44,7 +44,7 @@ public class BasicConfigurator {
     ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>();
     ca.setContext(lc);
     ca.setName("console");
-    PatternEncoder pl = new PatternEncoder();
+    PatternLayoutEncoder pl = new PatternLayoutEncoder();
     pl.setContext(lc);
     pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
     pl.start();
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/encoder/PatternEncoder.java b/logback-classic/src/main/java/ch/qos/logback/classic/encoder/PatternLayoutEncoder.java
similarity index 66%
rename from logback-classic/src/main/java/ch/qos/logback/classic/encoder/PatternEncoder.java
rename to logback-classic/src/main/java/ch/qos/logback/classic/encoder/PatternLayoutEncoder.java
index aea9f4a..c456e52 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/encoder/PatternEncoder.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/encoder/PatternLayoutEncoder.java
@@ -2,9 +2,9 @@ package ch.qos.logback.classic.encoder;
 
 import ch.qos.logback.classic.PatternLayout;
 import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.pattern.PatternEncoderBase;
+import ch.qos.logback.core.pattern.PatternLayoutEncoderBase;
 
-public class PatternEncoder extends PatternEncoderBase<ILoggingEvent> {
+public class PatternLayoutEncoder extends PatternLayoutEncoderBase<ILoggingEvent> {
 
   public void start() {
     layout = new PatternLayout();
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbclassic135/LoggingToFileThrouhput.java b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbclassic135/LoggingToFileThrouhput.java
index fa2c7eb..927557e 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbclassic135/LoggingToFileThrouhput.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbclassic135/LoggingToFileThrouhput.java
@@ -15,7 +15,7 @@ package ch.qos.logback.classic.issue.lbclassic135;
 
 import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.encoder.PatternEncoder;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.FileAppender;
 import ch.qos.logback.core.contention.ThreadedThroughputCalculator;
@@ -51,7 +51,7 @@ public class LoggingToFileThrouhput {
   static Logger buildLoggerContext(LoggerContext lc) {
     Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
 
-    PatternEncoder patternLayout = new PatternEncoder();
+    PatternLayoutEncoder patternLayout = new PatternLayoutEncoder();
     patternLayout.setContext(lc);
     patternLayout.setPattern("%d %l [%t] - %msg%n");
     patternLayout.start();
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 159d904..009490c 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
@@ -16,7 +16,7 @@ package ch.qos.logback.classic.multiJVM;
 import org.slf4j.Logger;
 
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.encoder.PatternEncoder;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.FileAppender;
 import ch.qos.logback.core.testUtil.RandomUtil;
@@ -33,7 +33,7 @@ public class FileAppenderPerf {
 
     FileAppender<ILoggingEvent> fa = new FileAppender<ILoggingEvent>();
 
-    PatternEncoder patternLayout = new PatternEncoder();
+    PatternLayoutEncoder patternLayout = new PatternLayoutEncoder();
     patternLayout.setPattern("%5p %c - %m%n");
     patternLayout.setContext(loggerContext);
     patternLayout.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 b33a635..afa7153 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
@@ -16,7 +16,7 @@ package ch.qos.logback.classic.multiJVM;
 import org.slf4j.Logger;
 
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.encoder.PatternEncoder;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.FileAppender;
 
@@ -58,7 +58,7 @@ public class SafeModeFileAppender {
 
     FileAppender<ILoggingEvent> fa = new FileAppender<ILoggingEvent>();
 
-    PatternEncoder patternLayout = new PatternEncoder();
+    PatternLayoutEncoder patternLayout = new PatternLayoutEncoder();
     patternLayout.setPattern(stamp + " %5p - %m%n");
     patternLayout.setContext(loggerContext);
     patternLayout.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 367e1f2..112f7d0 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
@@ -16,7 +16,7 @@ package ch.qos.logback.classic.multiJVM;
 import org.slf4j.Logger;
 
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.encoder.PatternEncoder;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.rolling.RollingFileAppender;
 import ch.qos.logback.core.rolling.TimeBasedRollingPolicy;
@@ -61,7 +61,7 @@ public class SafeModeRollingFileAppender {
     LoggerContext loggerContext = new LoggerContext();
 
     RollingFileAppender<ILoggingEvent> rfa = new RollingFileAppender<ILoggingEvent>();
-    PatternEncoder patternLayout = new PatternEncoder();
+    PatternLayoutEncoder patternLayout = new PatternLayoutEncoder();
     patternLayout.setPattern(stamp + " %5p - %-50m%n");
     patternLayout.setContext(loggerContext);
     patternLayout.start();
diff --git a/logback-core/src/main/java/ch/qos/logback/core/ConsoleAppender.java b/logback-core/src/main/java/ch/qos/logback/core/ConsoleAppender.java
index 24d31fe..bd1098e 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/ConsoleAppender.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/ConsoleAppender.java
@@ -86,7 +86,7 @@ public class ConsoleAppender<E> extends WriterAppender<E> {
      * implementation  because the console stream is not ours to close.
      */
     protected final void closeWriter() {
-      writeFooter();
+      encoderClose();
     }
   }
 
diff --git a/logback-core/src/main/java/ch/qos/logback/core/Encoder.java b/logback-core/src/main/java/ch/qos/logback/core/Encoder.java
index 87a7350..28cb9fc 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/Encoder.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/Encoder.java
@@ -23,6 +23,7 @@ public interface Encoder<E> extends ContextAware, LifeCycle {
   
   void doEncode(E event, OutputStream os) throws IOException;
 
+  void init(OutputStream os) throws IOException;
   void close(OutputStream os) throws IOException;
   
 }
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 c1f36e4..48b3090 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
@@ -31,13 +31,13 @@ import ch.qos.logback.core.status.ErrorStatus;
 public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
 
   protected Encoder<E> encoder;
-  
+
   /**
    * 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
+   * <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>
@@ -68,8 +68,8 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
   /**
    * 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.
+   * 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
@@ -96,14 +96,14 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
   public void start() {
     int errors = 0;
     if (this.encoder == null) {
-      addStatus(new ErrorStatus("No layout set for the appender named \""
+      addStatus(new ErrorStatus("No encoder set for the appender named \""
           + name + "\".", this));
       errors++;
     }
 
     if (this.outputStream == null) {
-      addStatus(new ErrorStatus("No output stream set for the appender named \""
-          + name + "\".", this));
+      addStatus(new ErrorStatus(
+          "No output stream set for the appender named \"" + name + "\".", this));
       errors++;
     }
     // only error free appenders should be activated
@@ -140,7 +140,7 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
     if (this.outputStream != null) {
       try {
         // before closing we have to output out layout's footer
-        writeFooter();
+        encoderClose();
         this.outputStream.close();
         this.outputStream = null;
       } catch (IOException e) {
@@ -152,10 +152,9 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
 
   /**
    * Returns an OutputStreamWriter when passed an OutputStream. The encoding
-   * used will depend on the value of the <code>encoding</code> property. If
-   * the encoding value is specified incorrectly the writer will be opened using
-   * the default system encoding (an error message will be printed to the
-   * loglog.
+   * used will depend on the value of the <code>encoding</code> property. If the
+   * encoding value is specified incorrectly the writer will be opened using the
+   * default system encoding (an error message will be printed to the loglog.
    */
   protected OutputStreamWriter createWriter(OutputStream os) {
     OutputStreamWriter retval = null;
@@ -184,20 +183,21 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
     encoding = value;
   }
 
-  void writeHeader() {
-    
-  }
-
-  private void appendIfNotNull(StringBuilder sb, String s) {
-    if (s != null) {
-      sb.append(s);
+  void encoderInit() {
+    if (encoder != null && this.outputStream != null) {
+      try {
+        encoder.init(outputStream);
+      } catch (IOException ioe) {
+        this.started = false;
+        addStatus(new ErrorStatus("Failed to write footer for appender named ["
+            + name + "].", this, ioe));
+      }
     }
   }
 
-  void writeFooter() {
+  void encoderClose() {
     if (encoder != null && this.outputStream != null) {
       try {
-        StringBuilder sb = new StringBuilder();
         encoder.close(outputStream);
       } catch (IOException ioe) {
         this.started = false;
@@ -210,8 +210,8 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
   /**
    * <p>
    * Sets the Writer where the log output will go. The specified Writer must be
-   * opened by the user and be writable. The <code>java.io.Writer</code> will
-   * be closed when the appender instance is closed.
+   * opened by the user and be writable. The <code>java.io.Writer</code> will be
+   * closed when the appender instance is closed.
    * 
    * @param writer
    *          An already opened Writer.
@@ -221,14 +221,22 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
     closeWriter();
 
     this.outputStream = outputStream;
-    writeHeader();
+    if(encoder == null) {
+      addWarn("Encoder not yet set. Cannot invoke init method ");
+      return;
+    }
+
+    try {
+      encoder.init(outputStream);
+    } catch (IOException e) {
+      addError("Failied to initialize encoder", e);
+    }
   }
 
-  
-  void writeOut(E event) throws IOException {
+  protected void writeOut(E event) throws IOException {
     this.encoder.doEncode(event, outputStream);
   }
-  
+
   /**
    * Actual writing occurs here.
    * <p>
@@ -242,7 +250,10 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
       return;
     }
     try {
-      writeOut(event);
+      // it is
+      synchronized (this) {
+        writeOut(event);
+      }
     } catch (IOException ioe) {
       // as soon as an exception occurs, move to non-started state
       // and add a single ErrorStatus to the SM.
@@ -258,6 +269,5 @@ public class WriterAppender<E> extends UnsynchronizedAppenderBase<E> {
   public void setEncoder(Encoder<E> encoder) {
     this.encoder = encoder;
   }
-  
-  
+
 }
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 8f99398..11d938b 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
@@ -3,15 +3,17 @@ package ch.qos.logback.core.html;
 import java.io.IOException;
 import java.io.OutputStream;
 
+import ch.qos.logback.core.CoreConstants;
 import ch.qos.logback.core.Encoder;
 import ch.qos.logback.core.Layout;
 import ch.qos.logback.core.spi.ContextAwareBase;
 
-public class LayoutWrappingEncoder<E> extends ContextAwareBase implements Encoder<E>  {
+public class LayoutWrappingEncoder<E> extends ContextAwareBase implements
+    Encoder<E> {
 
   boolean started;
   protected Layout<E> layout;
-  
+
   public Layout<E> getLayout() {
     return layout;
   }
@@ -20,7 +22,48 @@ public class LayoutWrappingEncoder<E> extends ContextAwareBase implements Encode
     this.layout = layout;
   }
 
+
+  public void init(OutputStream os) throws IOException {
+    writeHeader(os);
+  }
+
   public void close(OutputStream os) throws IOException {
+    writeFooter(os);
+  }
+
+  private void appendIfNotNull(StringBuilder sb, String s) {
+    if (s != null) {
+      sb.append(s);
+    }
+  }
+  
+  void writeHeader(OutputStream os) throws IOException {
+    if (layout != null && (os != null)) {
+      StringBuilder sb = new StringBuilder();
+      appendIfNotNull(sb, layout.getFileHeader());
+      appendIfNotNull(sb, layout.getPresentationHeader());
+      if (sb.length() > 0) {
+        sb.append(CoreConstants.LINE_SEPARATOR);
+        // If at least one of file header or presentation header were not
+        // null, then append a line separator.
+        // This should be useful in most cases and should not hurt.
+        os.write(sb.toString().getBytes());
+        os.flush();
+      }
+    }
+  }
+
+  void writeFooter(OutputStream os) throws IOException {
+    if (layout != null && os != null) {
+      StringBuilder sb = new StringBuilder();
+      appendIfNotNull(sb, layout.getPresentationFooter());
+      appendIfNotNull(sb, layout.getFileFooter());
+      if (sb.length() > 0) {
+        os.write(sb.toString().getBytes());
+        os.flush();
+      }
+
+    }
   }
 
   public void doEncode(E event, OutputStream os) throws IOException {
@@ -38,7 +81,7 @@ public class LayoutWrappingEncoder<E> extends ContextAwareBase implements Encode
   }
 
   public void stop() {
+    started = false;
   }
 
-
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternEncoderBase.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternEncoderBase.java
deleted file mode 100644
index a3bfc16..0000000
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternEncoderBase.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package ch.qos.logback.core.pattern;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-import ch.qos.logback.core.Encoder;
-import ch.qos.logback.core.spi.ContextAwareBase;
-
-public class PatternEncoderBase<E> extends ContextAwareBase implements Encoder<E> {
-
-  boolean started;
-  protected PatternLayoutBase<E> layout;
-  String pattern;
-  
-  public void close(OutputStream os) throws IOException {
-  }
-
-  public void doEncode(E event, OutputStream os) throws IOException {
-    String txt = layout.doLayout(event);
-    os.write(txt.getBytes());
-    os.flush();
-  }
-
-  public boolean isStarted() {
-    return false;
-  }
-
-  public void start() {
-    started = true;
-  }
-
-  public void stop() {
-  }
-
-  public String getPattern() {
-    return pattern;
-  }
-
-  public void setPattern(String pattern) {
-    this.pattern = pattern;
-  }
-
-  
-
-}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutEncoderBase.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutEncoderBase.java
new file mode 100644
index 0000000..5c90ac1
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutEncoderBase.java
@@ -0,0 +1,25 @@
+package ch.qos.logback.core.pattern;
+
+import ch.qos.logback.core.Layout;
+import ch.qos.logback.core.html.LayoutWrappingEncoder;
+
+public class PatternLayoutEncoderBase<E> extends LayoutWrappingEncoder<E> {
+
+  protected PatternLayoutBase<E> layout;
+  String pattern;
+
+  public String getPattern() {
+    return pattern;
+  }
+
+  public void setPattern(String pattern) {
+    this.pattern = pattern;
+  }
+
+  @Override
+  public void setLayout(Layout<E> layout) {
+    throw new UnsupportedOperationException("one cannot set the layout of "
+        + this.getClass().getName());
+  }
+
+}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/appender/DummyAppenderTest.java b/logback-core/src/test/java/ch/qos/logback/core/appender/DummyAppenderTest.java
index b728166..44f2f51 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/appender/DummyAppenderTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/appender/DummyAppenderTest.java
@@ -27,13 +27,13 @@ import ch.qos.logback.core.layout.DummyLayout;
 public class DummyAppenderTest extends AbstractAppenderTest<Object> {
 
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
-  
+  DummyWriterAppender<Object> da = new DummyWriterAppender<Object>(baos);
+   
   protected Appender<Object> getAppender() {
-    return new DummyAppender<Object>(baos);
+    return da;
   }
   
   protected Appender<Object> getConfiguredAppender() {
-    DummyAppender<Object> da = new DummyAppender<Object>(baos);
     da.setEncoder(new DummyEncoder<Object>());
     da.start();
     return da;
@@ -41,7 +41,6 @@ public class DummyAppenderTest extends AbstractAppenderTest<Object> {
 
   @Test
   public void testBasic() {
-    DummyAppender<Object> da = new DummyAppender<Object>(baos);
     da.setEncoder(new DummyEncoder<Object>());
     da.start();
     da.doAppend(new Object());
diff --git a/logback-core/src/test/java/ch/qos/logback/core/appender/DummyAppender.java b/logback-core/src/test/java/ch/qos/logback/core/appender/DummyWriterAppender.java
similarity index 85%
rename from logback-core/src/test/java/ch/qos/logback/core/appender/DummyAppender.java
rename to logback-core/src/test/java/ch/qos/logback/core/appender/DummyWriterAppender.java
index d2f0c82..c54ff3d 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/appender/DummyAppender.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/appender/DummyWriterAppender.java
@@ -17,10 +17,9 @@ import java.io.OutputStream;
 
 import ch.qos.logback.core.WriterAppender;
 
-public class DummyAppender<E> extends WriterAppender<E> {
+public class DummyWriterAppender<E> extends WriterAppender<E> {
 
-  DummyAppender(OutputStream os) {
+  DummyWriterAppender(OutputStream os) {
     this.setWriter(os);
   }
-
 }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/encoder/DummyEncoder.java b/logback-core/src/test/java/ch/qos/logback/core/encoder/DummyEncoder.java
index 2e82951..998ed52 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/encoder/DummyEncoder.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/encoder/DummyEncoder.java
@@ -42,15 +42,41 @@ public class DummyEncoder<E> extends EncoderBase<E> {
   }
 
   public void doEncode(E event, OutputStream os) throws IOException {
+    writeOut(os, val);
+  }
+
+  private void appendIfNotNull(StringBuilder sb, String s) {
+    if (s != null) {
+      sb.append(s);
+    }
+  }
+
+  void writeOut(OutputStream os, String s) throws IOException {
     if (encodingName == null) {
-      os.write(val.getBytes());
+      os.write(s.getBytes());
     } else {
-      os.write(val.getBytes(encodingName));
+      os.write(s.getBytes(encodingName));
     }
   }
 
+  void writeHeader(OutputStream os) throws IOException {
+    StringBuilder sb = new StringBuilder();
+    appendIfNotNull(sb, fileHeader);
+    if (sb.length() > 0) {
+      sb.append(CoreConstants.LINE_SEPARATOR);
+      // If at least one of file header or presentation header were not
+      // null, then append a line separator.
+      // This should be useful in most cases and should not hurt.
+      writeOut(os, sb.toString());
+    }
+  }
+
+  public void init(OutputStream os) throws IOException {
+    writeHeader(os);
+  }
+
   public void close(OutputStream os) throws IOException {
-    if(fileFooter == null) {
+    if (fileFooter == null) {
       return;
     }
     if (encodingName == null) {
diff --git a/logback-core/src/test/java/ch/qos/logback/core/encoder/EchoEncoder.java b/logback-core/src/test/java/ch/qos/logback/core/encoder/EchoEncoder.java
index 90c4b0c..5cc19f5 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/encoder/EchoEncoder.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/encoder/EchoEncoder.java
@@ -38,5 +38,10 @@ public class EchoEncoder<E> extends EncoderBase<E> {
     os.write(fileFooter.getBytes());
   }
 
-
+  public void init(OutputStream os) throws IOException {
+    if (fileHeader == null) {
+      return;
+    }
+    os.write(fileHeader.getBytes());
+  }
 }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/encoder/NopEncoder.java b/logback-core/src/test/java/ch/qos/logback/core/encoder/NopEncoder.java
index 8132f79..62afe4f 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/encoder/NopEncoder.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/encoder/NopEncoder.java
@@ -22,6 +22,8 @@ public class NopEncoder<E> extends EncoderBase<E> {
   }
 
   public void doEncode(E event, OutputStream os) throws IOException {
-    
+  }
+
+  public void init(OutputStream os) throws IOException {
   }
 }
diff --git a/logback-examples/src/main/java/chapter11/TrivialLogbackAppender.java b/logback-examples/src/main/java/chapter11/TrivialLogbackAppender.java
index 9ddfab6..e2b3d74 100644
--- a/logback-examples/src/main/java/chapter11/TrivialLogbackAppender.java
+++ b/logback-examples/src/main/java/chapter11/TrivialLogbackAppender.java
@@ -15,19 +15,19 @@ package chapter11;
 
 import java.io.IOException;
 
-import ch.qos.logback.classic.encoder.PatternEncoder;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.AppenderBase;
 
 public class TrivialLogbackAppender extends AppenderBase<ILoggingEvent> {
 
-  PatternEncoder encoder;
+  PatternLayoutEncoder encoder;
   
-  public PatternEncoder getEncoder() {
+  public PatternLayoutEncoder getEncoder() {
     return encoder;
   }
 
-  public void setEncoder(PatternEncoder encoder) {
+  public void setEncoder(PatternLayoutEncoder encoder) {
     this.encoder = encoder;
   }
 
diff --git a/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java b/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java
index 1df11e9..b4f0bec 100644
--- a/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java
+++ b/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java
@@ -15,7 +15,7 @@ package chapter4;
 
 import java.io.IOException;
 
-import ch.qos.logback.classic.encoder.PatternEncoder;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.AppenderBase;
 
@@ -25,7 +25,7 @@ public class CountingConsoleAppender extends AppenderBase<ILoggingEvent> {
   int counter = 0;
   int limit = DEFAULT_LIMIT;
   
-  PatternEncoder encoder;
+  PatternLayoutEncoder encoder;
   
   public CountingConsoleAppender() {
   }
@@ -62,11 +62,11 @@ public class CountingConsoleAppender extends AppenderBase<ILoggingEvent> {
     counter++;
   }
 
-  public PatternEncoder getEncoder() {
+  public PatternLayoutEncoder getEncoder() {
     return encoder;
   }
 
-  public void setEncoder(PatternEncoder encoder) {
+  public void setEncoder(PatternLayoutEncoder encoder) {
     this.encoder = encoder;
   }
   
diff --git a/logback-examples/src/main/java/chapter4/IO.java b/logback-examples/src/main/java/chapter4/IO.java
index 015bbff..fb989ce 100644
--- a/logback-examples/src/main/java/chapter4/IO.java
+++ b/logback-examples/src/main/java/chapter4/IO.java
@@ -16,7 +16,7 @@ package chapter4;
 import org.slf4j.Logger;
 
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.encoder.PatternEncoder;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.FileAppender;
 import ch.qos.logback.core.encoder.EchoEncoder;
@@ -47,7 +47,7 @@ public class IO extends Thread {
     FileAppender<ILoggingEvent> fa = new FileAppender<ILoggingEvent>();
 
     if (longMessage) {
-      PatternEncoder pa = new PatternEncoder();
+      PatternLayoutEncoder pa = new PatternLayoutEncoder();
       pa.setPattern("%r %5p %c [%t] - %m%n");
       pa.setContext(context);
       pa.start();
diff --git a/logback-examples/src/main/java/chapter5/PatternSample.java b/logback-examples/src/main/java/chapter5/PatternSample.java
index 6c7ec82..07b1ede 100644
--- a/logback-examples/src/main/java/chapter5/PatternSample.java
+++ b/logback-examples/src/main/java/chapter5/PatternSample.java
@@ -16,7 +16,7 @@ package chapter5;
 import org.slf4j.LoggerFactory;
 
 import ch.qos.logback.classic.Logger;
-import ch.qos.logback.classic.encoder.PatternEncoder;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.ConsoleAppender;
 
@@ -25,7 +25,7 @@ public class PatternSample {
   static public void main(String[] args) throws Exception {
     Logger rootLogger = (Logger) LoggerFactory.getLogger("root");
     
-    PatternEncoder layout = new PatternEncoder();
+    PatternLayoutEncoder layout = new PatternLayoutEncoder();
     layout.setPattern("%-5level [%thread]: %message%n");
     layout.start();
     
diff --git a/logback-examples/src/main/java/chapter7/SimpleMDC.java b/logback-examples/src/main/java/chapter7/SimpleMDC.java
index 304b7c3..228ae70 100644
--- a/logback-examples/src/main/java/chapter7/SimpleMDC.java
+++ b/logback-examples/src/main/java/chapter7/SimpleMDC.java
@@ -20,7 +20,7 @@ import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.encoder.PatternEncoder;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
 import ch.qos.logback.classic.joran.JoranConfigurator;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.ConsoleAppender;
@@ -63,7 +63,7 @@ public class SimpleMDC {
     LoggerContext loggerContext = (LoggerContext) LoggerFactory
         .getILoggerFactory();
     loggerContext.reset();
-    PatternEncoder layout = new PatternEncoder();
+    PatternLayoutEncoder layout = new PatternLayoutEncoder();
     layout.setContext(loggerContext);
     layout.setPattern("%X{first} %X{last} - %m%n");
     layout.start();

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

Summary of changes:
 ...tternEncoder.java => PatternLayoutEncoder.java} |    4 +-
 .../ch/qos/logback/access/jetty/JettyFixture.java  |    4 +-
 .../ch/qos/logback/classic/BasicConfigurator.java  |    4 +-
 ...tternEncoder.java => PatternLayoutEncoder.java} |    4 +-
 .../issue/lbclassic135/LoggingToFileThrouhput.java |    4 +-
 .../logback/classic/multiJVM/FileAppenderPerf.java |    4 +-
 .../classic/multiJVM/SafeModeFileAppender.java     |    4 +-
 .../multiJVM/SafeModeRollingFileAppender.java      |    4 +-
 .../java/ch/qos/logback/core/ConsoleAppender.java  |    2 +-
 .../src/main/java/ch/qos/logback/core/Encoder.java |    1 +
 .../java/ch/qos/logback/core/WriterAppender.java   |   72 +++++++++++---------
 .../logback/core/html/LayoutWrappingEncoder.java   |   49 +++++++++++++-
 .../logback/core/pattern/PatternEncoderBase.java   |   45 ------------
 .../core/pattern/PatternLayoutEncoderBase.java     |   25 +++++++
 .../logback/core/appender/DummyAppenderTest.java   |    7 +-
 ...DummyAppender.java => DummyWriterAppender.java} |    5 +-
 .../ch/qos/logback/core/encoder/DummyEncoder.java  |   32 ++++++++-
 .../ch/qos/logback/core/encoder/EchoEncoder.java   |    7 ++-
 .../ch/qos/logback/core/encoder/NopEncoder.java    |    4 +-
 .../java/chapter11/TrivialLogbackAppender.java     |    8 +-
 .../java/chapter4/CountingConsoleAppender.java     |    8 +-
 logback-examples/src/main/java/chapter4/IO.java    |    4 +-
 .../src/main/java/chapter5/PatternSample.java      |    4 +-
 .../src/main/java/chapter7/SimpleMDC.java          |    4 +-
 24 files changed, 187 insertions(+), 122 deletions(-)
 rename logback-access/src/main/java/ch/qos/logback/access/{PatternEncoder.java => PatternLayoutEncoder.java} (62%)
 rename logback-classic/src/main/java/ch/qos/logback/classic/encoder/{PatternEncoder.java => PatternLayoutEncoder.java} (66%)
 delete mode 100644 logback-core/src/main/java/ch/qos/logback/core/pattern/PatternEncoderBase.java
 create mode 100644 logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutEncoderBase.java
 rename logback-core/src/test/java/ch/qos/logback/core/appender/{DummyAppender.java => DummyWriterAppender.java} (85%)


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


More information about the logback-dev mailing list