[logback-dev] Layout setter/getter methods in AppenderBase

Ceki Gulcu ceki at qos.ch
Mon Feb 9 19:50:35 CET 2009


Hello all,

While working on chapter 11, migration of log4j appenders to
logback-classic, it occured to me that the current way AppenderBase
implements its layout setter and getter can be confusing. Here is the
relevant code:

abstract public class AppenderBase<E> extends ContextAwareBase implements
     Appender<E> {

   public Layout<E> getLayout() {
     return null;
   }

   public void setLayout(Layout<E> layout) {
   }

   // omitted code
}

The fact that the setLayout does nothing and getLayout always returns
null is somethat unexpected and may suprise users. This has apparently
already happended to Thilo Tanner as reported in LBCORE-56. See also
http://jira.qos.ch/browse/LBCORE-56

I'd like to change AppenderBase to:

abstract public class AppenderBase<E> extends ContextAwareBase implements
     Appender<E> {

   Layout<E> layout;

   public Layout<E> getLayout() {
     return layout;
   }

   public void setLayout(Layout<E> layout) {
     this.layout = layout;
   }

   // omitted code
}


The new code offers a reasonable default implementation for layout
getter and setter methods. It should decrease the aforementioned
surprise factor without causing harm to many appender implementations
which do not need a layout.

Comments?

-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch


More information about the logback-dev mailing list