On Oct 9, 2012, at 5:51 PM, Gary Gregory wrote: > On Tue, Oct 9, 2012 at 10:19 AM, Ralph Goers <[email protected]> > wrote: > 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(); > > ... > } > > I tried that refactoring and ran into one ugly: > > For org.apache.logging.log4j.core.layout.AbstractStringLayout.format(LogEvent) > > I had to change: > > public byte[] format(LogEvent event) { > return encoder.getBytes(formatAs(event)); > } > > to: > > public byte[] format(LogEvent event) { > return encoder.getBytes(formatAs(event).toString()); > } > > The change set is below. > > Thoughts?
Yeah. Instead of all of this just change Appender to Appender<?> getLayout(); BTW - none of these generics errors show up by default in IntelliJ nor are they flagged in Checkstyle or PMD. IntelliJ flags stuff that I don't fix. My goal is to have as few errors in the checkstyle report as possible. Ralph
