[ https://issues.apache.org/jira/browse/LOG4J2-1343?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15221488#comment-15221488 ]
Remko Popma edited comment on LOG4J2-1343 at 4/1/16 10:36 AM: -------------------------------------------------------------- Note to self on how to approach this (draft): AbstractOutputStreamAppender {code} public void append(final LogEvent event) { if (Constants.ENABLE_THREADLOCALS) { final ByteBufferDestination destination = manager.getByteBufferDestination(); getLayout().encode(event, destination); if (this.immediateFlush || event.isEndOfBatch()) { destination.drain(destination.getByteBuffer()); // write buffer to outputStream manager.flush(); } return; } ...// rest is same as before {code} OutputStreamManager {code} public class OutputStreamManager extends AbstractManager { private static final int DEFAULT_BUFFER_SIZE = 4 * 1024; private class ByteBufferDestinationAdapter implements ByteBufferDestination { private ByteBuffer buffer; @Override public ByteBuffer getByteBuffer() { if (buffer == null) { buffer = createByteBuffer(); } return buffer; } @Override public ByteBuffer drain(final ByteBuffer buf) { buf.flip(); write(buf.array(), 0, buf.limit(), false); buf.clear(); return buf; } } protected final Layout<?> layout; private volatile OutputStream os; private final ByteBufferDestination byteBufferDestination = new ByteBufferDestinationAdapter(); protected ByteBufferDestination getByteBufferDestination() { return byteBufferDestination; } // subclasses can override for different buffer size protected ByteBuffer createByteBuffer() { return ByteBuffer.wrap(new byte[DEFAULT_BUFFER_SIZE]); } ... /** * Writes the footer. */ protected void writeFooter() { // ensure all buffered data is written to the stream before writing footer final ByteBufferDestination destination = getByteBufferDestination(); destination.drain(destination.getByteBuffer()); if (layout == null) { return; } final byte[] footer = layout.getFooter(); if (footer != null) { write(footer); } } ... {code} was (Author: rem...@yahoo.com): Note to self on how to approach this (draft): AbstractOutputStreamAppender {code} public void append(final LogEvent event) { if (Constants.ENABLE_THREADLOCALS) { final ByteBufferDestination destination = manager.getByteBufferDestination(); getLayout().encode(event, destination); if (this.immediateFlush || event.isEndOfBatch()) { destination.drain(destination.getByteBuffer()); // write buffer to outputStream manager.flush(); } return; } ...// rest is same as before {code} OutputStreamManager {code} public class OutputStreamManager extends AbstractManager { private static final int DEFAULT_BUFFER_SIZE = 4 * 1024; private class ByteBufferDestinationAdapter implements ByteBufferDestination { private ByteBuffer buffer; @Override public ByteBuffer getByteBuffer() { if (buffer == null) { buffer = createByteBuffer(); } return buffer; } @Override public ByteBuffer drain(final ByteBuffer buf) { buf.flip(); write(buf.array(), 0, buf.limit(), false); buf.clear(); return buf; } } protected final Layout<?> layout; private volatile OutputStream os; private final ByteBufferDestination byteBufferDestination = new ByteBufferDestinationAdapter(); protected ByteBufferDestination getByteBufferDestination() { return byteBufferDestination; } // subclasses can override for different buffer size protected ByteBuffer createByteBuffer() { return ByteBuffer.wrap(new byte[DEFAULT_BUFFER_SIZE]); } ... // rest is same as before {code} > Update ConsoleAppender to utilize gc-free Layout method > ------------------------------------------------------- > > Key: LOG4J2-1343 > URL: https://issues.apache.org/jira/browse/LOG4J2-1343 > Project: Log4j 2 > Issue Type: Improvement > Components: Appenders > Affects Versions: 2.5 > Reporter: Remko Popma > > TBD: would we want to include this in the upcoming 2.6 release? -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org