logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maciej Kara? (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1030) Header in layout created every time application starts
Date Wed, 27 May 2015 09:31:17 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1030?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14560683#comment-14560683
] 

Maciej Kara? commented on LOG4J2-1030:
--------------------------------------

I cannot agree. The documentation for header in LayoutPattern says it is included at the top
of each log file. The current behaviour is misleading and not conforming to documentation.
https://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout 

> 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?
>
> 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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message