You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Remko Popma <re...@gmail.com> on 2016/04/20 10:49:53 UTC

Re: GC-free and CSV

(Including log4j-dev list)

For a Layout to be garbage-free it needs to override encode(LogEvent,
ByteBufferDestination).

Generally, Layouts that extend AbstractStringLayout have two jobs: building
a text representation of the LogEvent, and turning that text into bytes.

The latter part can be done garbage-free by using StringBuilderEncoder.

To build a CSV text representation of the LogEvent without generating
garbage, you need to cache  a ThreadLocal StringBuilder and append the
parameters while preserving the quoting rules the user specified in
configuration. This may mean reimplementing some of the Commons CSV logic
since I don't think that library is garbage-free.

There's one issue that the current code in master does not correctly
preserve parameters with async logging:
https://issues.apache.org/jira/browse/LOG4J2-1342.
I'm working on that one and hope to commit a fix in the next few days.

Remko

On Wednesday, 20 April 2016, Gary Gregory <ga...@gmail.com> wrote:

> Hi,
>
> The guts of the CSV layout is really about appending to an Appendable.
>
> With the new code in master, can this layout be made to write directly to
> whatever is the endpoint/stream thingy?
>
> Gary
>
> --
> E-Mail: garydgregory@gmail.com
> <javascript:_e(%7B%7D,'cvml','garydgregory@gmail.com');> | ggregory@apache.org
> <javascript:_e(%7B%7D,'cvml','ggregory@apache.org');>
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>