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

Joern Huxhorn jhuxhorn at googlemail.com
Mon Feb 9 22:43:37 CET 2009


Hi Ceki,

the only thing that I don't understand is why Appender requires a  
layout at all.
It would by cleaner if there was a sub-interface, e.g.  
LayoutAwareAooender (just a spontaneous suggestion), that extended  
Appender and would add said methods.
Some appenders, like SocketAppender or some fictitious appender that  
would simply serialize the events to a file (I'm planning to implement  
such an appender, btw), just don't need a layout at all.
AppenderBase would then just implement the basic Appender interface,  
leaving the layout implementation to appenders that would really  
require it.

This topic is covered by both http://jira.qos.ch/browse/LBCORE-1 and http://jira.qos.ch/browse/LBCORE-56

Regards,
Joern.

On 09.02.2009, at 19:50, Ceki Gulcu wrote:

> 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
> _______________________________________________
> logback-dev mailing list
> logback-dev at qos.ch
> http://qos.ch/mailman/listinfo/logback-dev



More information about the logback-dev mailing list