[logback-dev] svn commit: r1914 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core test/java/ch/qos/logback/core/appender

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Oct 29 21:03:59 CET 2008


Author: ceki
Date: Wed Oct 29 21:03:58 2008
New Revision: 1914

Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/appender/DummyAppender.java

Log:

The writer field in WriterAppender has been marked as private, as suggested by Anders Hammar in LBCORE-34

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java	Wed Oct 29 21:03:58 2008
@@ -13,6 +13,7 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.Writer;
 
 import ch.qos.logback.core.status.ErrorStatus;
 import ch.qos.logback.core.status.InfoStatus;
@@ -87,14 +88,14 @@
   public void start() {
     int errors = 0;
     if (fileName != null) {
-      addInfo("filename set to ["+fileName+"]");
-      
+      addInfo("filename set to [" + fileName + "]");
+
       // 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) {
-        immediateFlush = false;
+        setImmediateFlush(false);
         addStatus(new InfoStatus(
             "Setting immediateFlush to false on account of bufferedIO option",
             this));
@@ -118,22 +119,20 @@
   }
 
   /**
-   * <p>
-   * Sets and <i>opens</i> the file where the log output will go. The specified
-   * file must be writable.
+   * <p> Sets and <i>opens</i> the file where the log output will go. The
+   * specified file must be writable.
    * 
-   * <p>
-   * If there was already an opened file, then the previous file is closed
+   * <p> If there was already an opened file, then the previous file is closed
    * first.
    * 
-   * <p>
-   * <b>Do not use this method directly. To configure a FileAppender or one of
-   * its subclasses, set its properties one by one and then call start().</b>
+   * <p> <b>Do not use this method directly. To configure a FileAppender or one
+   * of its subclasses, set its properties one by one and then call start().</b>
    * 
    * @param filename
-   *          The path to the log file.
+   *                The path to the log file.
    * @param append
-   *          If true will append to fileName. Otherwise will truncate fileName.
+   *                If true will append to fileName. Otherwise will truncate
+   *                fileName.
    * @param bufferedIO
    * @param bufferSize
    * 
@@ -141,21 +140,20 @@
    * 
    */
   public synchronized void openFile() throws IOException {
-    closeWriter();
-
     File file = new File(fileName);
-    if(FileUtil.mustCreateParentDirectories(file)) {
+    if (FileUtil.mustCreateParentDirectories(file)) {
       boolean result = FileUtil.createMissingParentDirectories(file);
-      if(!result) {
-        addError("Failed to create parent directories for ["+file.getAbsolutePath()+"]");
+      if (!result) {
+        addError("Failed to create parent directories for ["
+            + file.getAbsolutePath() + "]");
       }
     }
-    
-    this.writer = createWriter(new FileOutputStream(fileName, append));
+
+    Writer w = createWriter(new FileOutputStream(fileName, append));
     if (bufferedIO) {
-      this.writer = new BufferedWriter(this.writer, bufferSize);
+      w = new BufferedWriter(w, bufferSize);
     }
-    writeHeader();
+    setWriter(w);
   }
 
   public boolean isBufferedIO() {

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java	Wed Oct 29 21:03:58 2008
@@ -1,12 +1,13 @@
 /**
- * Logback: the reliable, generic, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
  * 
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 2000-2008, QOS.ch
  * 
  * This library is free software, you can redistribute it and/or modify it under
  * the terms of the GNU Lesser General Public License as published by the Free
  * Software Foundation.
  */
+
 package ch.qos.logback.core;
 
 import java.io.IOException;
@@ -39,7 +40,7 @@
    * The <code>immediateFlush</code> variable is set to <code>true</code> by
    * default.
    */
-  protected boolean immediateFlush = true;
+  private boolean immediateFlush = true;
 
   /**
    * The encoding to use when opening an InputStream.
@@ -47,18 +48,18 @@
    * The <code>encoding</code> variable is set to <code>null</null> by default 
    * which results in the use of the system's default encoding.
    */
-  protected String encoding;
+  private String encoding;
 
   /**
    * This is the {@link Writer Writer} where we will write to.
    */
-  protected Writer writer;
+  private Writer writer;
 
   /**
    * The layout variable does not need to be set if the appender implementation
    * has its own layout.
    */
-  protected Layout<E> layout;
+  private Layout<E> layout;
 
   /**
    * The default constructor does nothing.

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/appender/DummyAppender.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/appender/DummyAppender.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/appender/DummyAppender.java	Wed Oct 29 21:03:58 2008
@@ -1,11 +1,11 @@
 /**
- * LOGBack: the reliable, fast and flexible logging library for Java.
- *
- * Copyright (C) 1999-2006, QOS.ch
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2008, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
  */
 package ch.qos.logback.core.appender;
 
@@ -15,11 +15,8 @@
 
 public class DummyAppender<E> extends WriterAppender<E> {
 
-  
   DummyAppender(Writer writer) {
-    this.writer = writer;
+    this.setWriter(writer);
   }
-  
-  
-  
+
 }


More information about the logback-dev mailing list