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

No header output in RollingRandomAccessFile

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0-rc1
    • 2.0-rc2
    • Appenders

    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.

      Attachments

        Issue Links

          Activity

            People

              rpopma Remko Popma
              mailer67 Alexander Khokhlov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: