Description
Header is appended to OutputStream every time Appender/Manager constructor is called. This causes appending header every time application restarts which I think is wrong. Examples:
protected OutputStreamManager(final OutputStream os, final String streamName, final Layout<?> layout) { super(streamName); this.os = os; this.layout = layout; if (layout != null) { final byte[] header = layout.getHeader(); if (header != null) { try { this.os.write(header, 0, header.length); } catch (final IOException ioe) { LOGGER.error("Unable to write header", ioe); } } } }
public RollingRandomAccessFileManager(final RandomAccessFile raf, final String fileName, final String pattern, final OutputStream os, final boolean append, final boolean immediateFlush, final int bufferSize, final long size, final long time, final TriggeringPolicy policy, final RolloverStrategy strategy, final String advertiseURI, final Layout<? extends Serializable> layout) { super(fileName, pattern, os, append, size, time, policy, strategy, advertiseURI, layout, bufferSize); this.isImmediateFlush = immediateFlush; this.randomAccessFile = raf; isEndOfBatch.set(Boolean.FALSE); this.buffer = ByteBuffer.allocate(bufferSize); writeHeader(); }
I think header should be appended to the file only once. It might be configurable if one wants to append header after application restart.
Attachments
Issue Links
- duplicates
-
LOG4J2-889 RollingRandomAccessFileAppender appends the header every time the application is started.
- Resolved