<div class="gmail_quote">On Fri, Feb 13, 2009 at 3:25 PM, Ceki Gulcu <span dir="ltr">&lt;ceki@qos.ch&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi Maarteen,<br>
<br>
I really like the idea of pluggable encoders. </blockquote><div><br>Great.<br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Putting UnsyncronizedAppenderBase aside for a second, I could imagine the following class hierarchy:<br>

<br>
interface LayoutAware extends Appender;<br>
interface EncoderAware extends Appender;</blockquote><div><br>I don&#39;t understand.<br>In my opinion LayoutAware and EncoderAware should be standalone interface with just a getter and a setter, and not extend Appender.<br>
<br>All appenders that need a layout should implement LayoutAware.<br>They can implement the interface themselves or - when its practical - inherit from LayoutAwareAppenderBase<br><br>Why would you tie LayoutAware to the Appender interface.<br>
<br>Imagine this Encoder implementation:&nbsp; it implements layoutAware but it&#39;s not an Appender<br><br>public class LayoutBasedEncoder implements Encoder, LayoutAware {<br>&nbsp; private Layout layout;<br>&nbsp; public Layout getLayout() {...}<br>
&nbsp; public void setLayout(...) {...}<br><br>&nbsp; public ByteBuffer encode(LoggingEvent event) {<br>&nbsp;&nbsp;&nbsp; String str = layout.format(event);<br>&nbsp;&nbsp;&nbsp; byte[] bytes = getUtf8Bytes(str);<br>&nbsp;&nbsp;&nbsp; ByteBuffer buffer = ByteBuffer.allocate(bytes.length + 4);<br>
&nbsp;&nbsp;&nbsp; buffer.putInt(bytes.length);<br>&nbsp;&nbsp;&nbsp; buffer.put(bytes);<br>&nbsp;&nbsp;&nbsp; return buffer;<br>&nbsp; }<br><br>}<br><br>PS:&nbsp; Not yet sure whether the encode method should return a byte[] or a java.nio.ByteBuffer, I think the latter is easier to use.<br>
<br>regards,<br>Maarten<br></div><br><div>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
abstract class AppenderBase implements Appender;<br>
abstract class LayoutAwareAppenderBase ext. AppenderBase implements LayoutAware;<br>
abstract class EncodrAwareAppenderBase ext. AppenderBase implements LayoutAware;<br>
<br>
class WriterAppender extends LayoutAwareAppenderBase;<br>
class FileAppender extends WriterAppender;<br>
...<br>
class SocketAppender extends EncoderAwareAppenderBase;<br>
<br>
Appenders such as DBAppender and SMTPAppender, where LoggingEvent to byte[] encoding nor layouts make sense, could extend AppenderBase directly.<br>
<br>
We should pursue this....<div class="Ih2E3d"><br>
<br>
Maarten Bosteels wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello,<br>
<br>
I agree with Joern, it would be cleaner to have a LayoutAware interface, and only appenders that use a Layout should implement it.<br>
The way it is now, people can set a layout on the SocketAppender, they don&#39;t get an exception, but the layout would never be used.<br>
<br>
I can understand the &quot;historical&quot; reasons, but IMO things like this can be changed as long as logback doesn&#39;t reach 1.0Maarten<br>
<br>
Related idea/proposal: &nbsp;an Encoder interface similar to Layout but returning a byte array instead of a String:<br>
<br>
public interface Encoder {<br>
 &nbsp;byte[] encode(LoggingEvent event)<br>
}<br>
<br>
I recently worked on an AsyncSocketAppender (extending UnsyncronizedAppenderBase) and with this interface the wire-format would be pluggable.<br>
<br>
Some wire-formats I am thinking about: &nbsp;Apache Thrift, Google protobuf and of course Java serialization.<br>
<br>
I still have to implement these encoders and compare their perfomance. &nbsp;I will let you know when I get there.<br>
<br>
It would be really cool if we could define a wire-format based on Protobuf and/or Thrift that could also be used for encoding log4j events.<br>
But I guess it would be better to do this in a separate project ...<br>
<br>
regards,<br>
Maarten<br>
</blockquote>
<br></div><div><div></div><div class="Wj3C7c">
-- <br>
Ceki Gülcü<br>
Logback: The reliable, generic, fast and flexible logging framework for Java.<br>
<a href="http://logback.qos.ch" target="_blank">http://logback.qos.ch</a><br>
_______________________________________________<br>
logback-dev mailing list<br>
logback-dev@qos.ch<br>
<a href="http://qos.ch/mailman/listinfo/logback-dev" target="_blank">http://qos.ch/mailman/listinfo/logback-dev</a><br>
</div></div></blockquote></div><br>