Log4j 2
  1. Log4j 2
  2. LOG4J2-581

No header output in RollingRandomAccessFile

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-rc1
    • Fix Version/s: 2.0-rc2
    • Component/s: Appenders
    • Labels:

      Description

      No header output in RollingRandomAccessFile due to DummyOutputStream used when creating RollingRandomAccessFileManager.

      RollingRandomAccessFileManager.java
      ...
      162:                return new RollingRandomAccessFileManager(raf, name, data.pattern, +new DummyOutputStream()+, data.append,
      163:                        data.immediateFlush, size, time, data.policy, data.strategy, data.advertiseURI, data.layout);
      

      When the superclass constructor (OutputStreamManager) writes header, it outputs thus header to nowhere:

      OutputStreamManager.java
      35:    protected OutputStreamManager(final OutputStream os, final String streamName, final Layout<?> layout) {
      36:        super(streamName);
      37:        this.os = os;
      38:        if (layout != null) {
      39:            this.footer = layout.getFooter();
      40:            this.header = layout.getHeader();
      41:            if (this.header != null) {
      42:                try {
      43:!!!                 this.os.write(header, 0, header.length);
      44:                } catch (final IOException ioe) {
      45:                    LOGGER.error("Unable to write header", ioe);
      46:                }
      47:            }
      48:        } else {
      49:            this.footer = null;
      50:            this.header = null;
      51:        }
      52:    }
      

      The same fragment from RollingFileManager.java where header output works fine:

      RollingFileManager.java
      306:                os = new FileOutputStream(name, data.append);
      307:                if (data.bufferedIO) {
      308:                    os = new BufferedOutputStream(os);
      309:                }
      310:                final long time = file.lastModified(); // LOG4J2-531 create file first so time has valid value
      311:                return new RollingFileManager(name, data.pattern, +os+, data.append, size, time, data.policy,
      312:                    data.strategy, data.advertiseURI, data.layout);
      

      In this case the "os" variable is a real stream which points to the file.

        Issue Links

          Activity

          Alexander Khokhlov created issue -
          Alexander Khokhlov made changes -
          Field Original Value New Value
          Description No header output in RollingRandomAccessFile due to DummyOutputStream used when creating RollingRandomAccessFileManager.
          {code:title=RollingRandomAccessFileManager.java}
          ...
          162: return new RollingRandomAccessFileManager(raf, name, data.pattern, +new DummyOutputStream()+, data.append,
          163: data.immediateFlush, size, time, data.policy, data.strategy, data.advertiseURI, data.layout);
          {code}
          When the superclass constructor (OutputStreamManager) writes header, it outputs thus header to nowhere:
          {code:title=OutputStreamManager.java}
          35: protected OutputStreamManager(final OutputStream os, final String streamName, final Layout<?> layout) {
          36: super(streamName);
          37: this.os = os;
          38: if (layout != null) {
          39: this.footer = layout.getFooter();
          40: this.header = layout.getHeader();
          41: if (this.header != null) {
          42: try {
          43: this.os.write(header, 0, header.length);
          44: } catch (final IOException ioe) {
          45: LOGGER.error("Unable to write header", ioe);
          46: }
          47: }
          48: } else {
          49: this.footer = null;
          50: this.header = null;
          51: }
          52: }
          {code}
          The same fragment from RollingFileManager.java where header output works fine:
          {code:title=RollingFileManager.java}
          306: os = new FileOutputStream(name, data.append);
          307: if (data.bufferedIO) {
          308: os = new BufferedOutputStream(os);
          309: }
          310: final long time = file.lastModified(); // LOG4J2-531 create file first so time has valid value
          311: return new RollingFileManager(name, data.pattern, os, data.append, size, time, data.policy,
          312: data.strategy, data.advertiseURI, data.layout);
          {code}

          In this case the "os" variable is a real stream which points to the file.
          No header output in RollingRandomAccessFile due to DummyOutputStream used when creating RollingRandomAccessFileManager.
          {code:title=RollingRandomAccessFileManager.java}
          ...
          162: return new RollingRandomAccessFileManager(raf, name, data.pattern, +new DummyOutputStream()+, data.append,
          163: data.immediateFlush, size, time, data.policy, data.strategy, data.advertiseURI, data.layout);
          {code}
          When the superclass constructor (OutputStreamManager) writes header, it outputs thus header to nowhere:
          {code:title=OutputStreamManager.java}
          35: protected OutputStreamManager(final OutputStream os, final String streamName, final Layout<?> layout) {
          36: super(streamName);
          37: this.os = os;
          38: if (layout != null) {
          39: this.footer = layout.getFooter();
          40: this.header = layout.getHeader();
          41: if (this.header != null) {
          42: try {
          43:!!! this.os.write(header, 0, header.length);
          44: } catch (final IOException ioe) {
          45: LOGGER.error("Unable to write header", ioe);
          46: }
          47: }
          48: } else {
          49: this.footer = null;
          50: this.header = null;
          51: }
          52: }
          {code}
          The same fragment from RollingFileManager.java where header output works fine:
          {code:title=RollingFileManager.java}
          306: os = new FileOutputStream(name, data.append);
          307: if (data.bufferedIO) {
          308: os = new BufferedOutputStream(os);
          309: }
          310: final long time = file.lastModified(); // LOG4J2-531 create file first so time has valid value
          311: return new RollingFileManager(name, data.pattern, +os+, data.append, size, time, data.policy,
          312: data.strategy, data.advertiseURI, data.layout);
          {code}

          In this case the "os" variable is a real stream which points to the file.
          Alexander Khokhlov made changes -
          Affects Version/s 2.0-rc1 [ 12325011 ]
          Affects Version/s 2.0-rc2 [ 12326292 ]
          Alexander Khokhlov made changes -
          Affects Version/s 2.0-rc2 [ 12326292 ]
          Remko Popma made changes -
          Labels Rollover
          Remko Popma made changes -
          Assignee Remko Popma [ remkop@yahoo.com ]
          Remko Popma made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Remko Popma made changes -
          Link This issue relates to LOG4J2-675 [ LOG4J2-675 ]
          Remko Popma made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Fix Version/s 2.0-rc2 [ 12326292 ]
          Resolution Fixed [ 1 ]
          Remko Popma made changes -
          Link This issue relates to LOG4J2-569 [ LOG4J2-569 ]

            People

            • Assignee:
              Remko Popma
              Reporter:
              Alexander Khokhlov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development