[
https://issues.apache.org/jira/browse/LOG4J2-1030?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Maciej Kara? updated LOG4J2-1030:
---------------------------------
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:
{code:java}
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);
}
}
}
}
{code}
{code:java}
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();
}
{code}
I think header should be appended to the file only once. It might be
configurable if one wants to append header after application restart.
was:
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:
{code:java}
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);
}
}
}
}
{code:java}
{code:java}
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();
}
{code:java}
I think header should be appended to the file only once. It might be
configurable if one wants to append header after application restart.
> Header in layout created every time application starts
> ------------------------------------------------------
>
> Key: LOG4J2-1030
> URL: https://issues.apache.org/jira/browse/LOG4J2-1030
> Project: Log4j 2
> Issue Type: Bug
> Components: Appenders, Core, Layouts
> Affects Versions: 2.3
> Reporter: Maciej Kara?
> Priority: Critical
>
> 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:
> {code:java}
> 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);
> }
> }
> }
> }
> {code}
> {code:java}
> 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();
> }
> {code}
> I think header should be appended to the file only once. It might be
> configurable if one wants to append header after application restart.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]