This requires a long answer.

Ceki realized in Logback that OutputStreams really needed a byte array.  So he 
changed Appenders to require an Encoder instead of an Appender.  Layouts still 
return a String so he created a wrapper Encoder to convert the String to a byte 
array.

The idea of using a byte array is correct - most of the time, as most of the 
Appenders use an OutputStream.  However, the JMS appenders don't. They require 
a Serializable object.  

When developing Log4j I did not like having both Encoders and Layouts, so I 
chose to have Layouts return a byte array. But then it made no sense to have 
something based on the AbstractStringLayout convert the String to a byte array 
only to have to convert it back to a String again for the JMS Appenders, which 
is why I added formatAs().  Now the JMS Appender can send both a Serialized 
LogEvent and a String.

So in looking at how formatAs() is used I would think that we could just change 
Layout to

public interface Layout {

    Serializable formatAs();

    ...
}



On Oct 9, 2012, at 6:23 AM, Gary Gregory wrote:

> Hi All:
> 
> We currently have a generics warning for:
> 
> org.apache.logging.log4j.core.Appender.getLayout()
> 
> because the method is defined as:
> 
> Layout getLayout();
> 
> and Layout<T extends Serializable>
> 
> Which hints at defining getLayout() as:
> 
> Layout<T> getLayout();
> 
> Which means either:
> 
> <T extends Serializable> Layout<T> getLayout();
> 
> or:
> 
> public interface Appender<T extends Serializable> extends Lifecycle {
> ...
> Layout<T> getLayout();
> 
> Now I also see:
> 
> @issue LOG4J2-36 Refactor into Channel
> 
> But the issue has been closed with no changes planned. 
> 
> So... thoughts?
> 
> Gary
> 
> 
> 
> 
> -- 
> E-Mail: [email protected] | [email protected] 
> JUnit in Action, 2nd Ed: http://bit.ly/ECvg0
> Spring Batch in Action: http://bit.ly/bqpbCK
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory

Reply via email to