I sent an e-mail with this subject several months ago.  That e-mail
described the changes I made to a Log4J 1.1.3 base for a customer I was
working at.  There was alot of interest in the changes I described.
Unfortunately the client would not allow me to release the code changes
back to the open source group.

I finally got around to refactoring these changes into 1.2.7.  They are not
fully tested and should be considered a prototype.  It does not contain all
of the changes I described in my last e-mail.  This refactoring replaces
the use of StringBuffer with Writer.  I tested with
DailyRollingFileAppender.  Instead of writing an extra copy in memory to a
StringBuffer it is written to the QuietWriter, which is backed by a
BufferedWriter in DailyRollingFileAppender.  This is a win in speed(one
less copy) and in memory(there is no StringBuffer).

Here are a list of the files changed:

Layout:  Adds "stream(LoggingEvent, Writer)" to replace
"format(LoggingEvent)".  This is where the proposed change uses less memory
by using a writer instead of a StringBuffer.

PatternLayout, SimpleLayout, TTCCLayout, XMLLayout:
The "stream" method looks very similar to format where sb.append(string) is
replaced with out.write(string).

HTMLLayout:
Also adds a HTMLThrowablePrintWriter.  Better memory usage and shorter
execution path than using ThrowableInformation.getThrowableStrRep(..).
Questionable if using multiple appenders.

PatternConverter:  Adds "format(LoggingEvent, Writer)" to replace
"format(StringBuffer, LoggingEvent)" and "convert(LoggingEvent, Writer)" to
replace "convert(LoggingEvent)".  Responsibility to output pattern falls to
convert method.  Convinience method added to format String to a Writer, was
done in "format" but now this is called from "convert" method.

PatternParser:  Inner classes extending PatternConverter have new format
method


WriterAppender:  Changed to use the new "stream" method from layout passing
in the QuietWriter.  Instead of using ThrowableInformation to get the stack
trace, Throwable.printStackTrace is called directly.

FileAppender:  Changed to delegate creation of QuietWriter to
WriterAppender.  WriterAppender has a new PrintWriter set up at the same
time and needs to be notified when the QuietWriter is created.




If an appender needs a "String" from the layout it could send in a
"StringWriter" and basically have the same end result as using a
StringBuffer.

If there's more interest in these changes I'm willing to talk about them.

(See attached file: log4j_1.2.7_updates.zip)

Chris Nokes
Perficient, Inc

Attachment: log4j_1.2.7_updates.zip
Description: Zip archive

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to