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

          Hide
          Remko Popma added a comment -

          I can take a look, but it would be great if you could provide a patch. Do you think you'll have time for that?

          Show
          Remko Popma added a comment - I can take a look, but it would be great if you could provide a patch. Do you think you'll have time for that?
          Hide
          Remko Popma added a comment -

          Fixed in revision 1604428.

          Please verify and close.

          Show
          Remko Popma added a comment - Fixed in revision 1604428. Please verify and close.

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development