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
- relates to
-
LOG4J2-569 Configuring RollingRandomAccessFile with HTMLLayout does not work as expected
- Resolved
-
LOG4J2-675 RollingFile and RollingRandomAccessFile don't write footer before rollover
- Closed