Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1030

Header in layout created every time application starts

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3
    • 2.4
    • Appenders, Core, Layouts
    • None

    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

          Activity

            People

              rpopma Remko Popma
              truecurry Maciej Karaƛ
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: