[logback-dev] svn commit: r2146 - in logback/trunk: logback-core/src/main/java/ch/qos/logback/core logback-core/src/main/java/ch/qos/logback/core/net logback-examples/src/main/java/chapter4

noreply.ceki at qos.ch noreply.ceki at qos.ch
Mon Feb 9 21:17:21 CET 2009


Author: ceki
Date: Mon Feb  9 21:17:21 2009
New Revision: 2146

Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/WriterAppender.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SyslogAppenderBase.java
   logback/trunk/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java

Log:
The layout setter and getter methods in AppenderBase now actually set a 
field called layout.  This is related to LBCORE-56 

See also http://qos.ch/pipermail/logback-dev/2009-February/003660.html

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java	Mon Feb  9 21:17:21 2009
@@ -28,6 +28,12 @@
 abstract public class AppenderBase<E> extends ContextAwareBase implements
     Appender<E> {
 
+  /**
+   * The layout variable does not need to be set depending on the appender. Some
+   * appenders do not need a layout.
+   */
+  protected Layout<E> layout;
+
   protected boolean started = false;
 
   /**
@@ -129,15 +135,24 @@
   public List<Filter<E>> getCopyOfAttachedFiltersList() {
     return fai.getCopyOfAttachedFiltersList();
   }
-  
+
   public FilterReply getFilterChainDecision(E event) {
     return fai.getFilterChainDecision(event);
   }
 
+  /**
+   * Returns the layout of this appender. The returned value may be null if this
+   * appender does not have a layout.
+   */
   public Layout<E> getLayout() {
-    return null;
+    return layout;
   }
 
+  /**
+   * Set the layout for this appender. Note that some appenders have their own
+   * (fixed) layouts or do not use any.
+   */
   public void setLayout(Layout<E> layout) {
+    this.layout = layout;
   }
 }

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	Mon Feb  9 21:17:21 2009
@@ -53,11 +53,6 @@
    */
   private Writer writer;
 
-  /**
-   * The layout variable does not need to be set if the appender implementation
-   * has its own layout.
-   */
-  private Layout<E> layout;
 
   /**
    * The default constructor does nothing.
@@ -182,20 +177,6 @@
     encoding = value;
   }
 
-  /**
-   * Set the layout for this appender. Note that some appenders have their own
-   * (fixed) layouts or do not use any.
-   */
-  public void setLayout(Layout<E> layout) {
-    this.layout = layout;
-  }
-
-  /**
-   * Returns the layout of this appender. The value may be null.
-   */
-  public Layout<E> getLayout() {
-    return layout;
-  }
 
   void writeHeader() {
     if (layout != null && (this.writer != null)) {

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java	Mon Feb  9 21:17:21 2009
@@ -48,7 +48,6 @@
  */
 public abstract class SMTPAppenderBase<E> extends AppenderBase<E> {
 
-  protected Layout<E> layout;
   protected Layout<E> subjectLayout;
 
   private List<String> to = new ArrayList<String>();
@@ -391,14 +390,6 @@
     this.eventEvaluator = eventEvaluator;
   }
 
-  public Layout<E> getLayout() {
-    return layout;
-  }
-
-  public void setLayout(Layout<E> layout) {
-    this.layout = layout;
-  }
-
   public String getUsername() {
     return username;
   }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SyslogAppenderBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SyslogAppenderBase.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SyslogAppenderBase.java	Mon Feb  9 21:17:21 2009
@@ -30,7 +30,6 @@
   final static String SYSLOG_LAYOUT_URL = CoreConstants.CODES_URL + "#syslog_layout";
   final static int MSG_SIZE_LIMIT = 256*1024;
   
-  Layout<E> layout;
   int facility;
   String facilityStr;
   String syslogHost;
@@ -207,10 +206,12 @@
   }
 
 
+  @Override
   public Layout<E> getLayout() {
     return layout;
   }
 
+  @Override
   public void setLayout(Layout<E> layout) {
     addWarn("The layout of a SyslogAppender cannot be set directly. See also "+SYSLOG_LAYOUT_URL);
   }

Modified: logback/trunk/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java	(original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/CountingConsoleAppender.java	Mon Feb  9 21:17:21 2009
@@ -12,7 +12,6 @@
 
 import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.core.AppenderBase;
-import ch.qos.logback.core.Layout;
 
 
 public class CountingConsoleAppender extends AppenderBase<LoggingEvent> {
@@ -20,8 +19,6 @@
   int counter = 0;
   int limit = DEFAULT_LIMIT;
   
-  private Layout<LoggingEvent> layout;
-
   public CountingConsoleAppender() {
   }
 
@@ -44,23 +41,13 @@
   }
 
   public void append(LoggingEvent event) {
-
     if (counter >= limit) {
       return;
     }
-
     // output the events as formatted by our layout
     System.out.print(this.layout.doLayout(event));
 
     // prepare for next event
     counter++;
   }
-
-  public Layout<LoggingEvent> getLayout() {
-    return layout;
-  }
-
-  public void setLayout(Layout<LoggingEvent> layout) {
-    this.layout = layout;
-  }
 }


More information about the logback-dev mailing list