You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Alexander Khokhlov (JIRA)" <ji...@apache.org> on 2014/03/26 18:59:15 UTC

[jira] [Updated] (LOG4J2-581) No header output in RollingRandomAccessFile

     [ https://issues.apache.org/jira/browse/LOG4J2-581?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexander Khokhlov updated LOG4J2-581:
--------------------------------------

    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.

  was:
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
> -------------------------------------------
>
>                 Key: LOG4J2-581
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-581
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>            Reporter: Alexander Khokhlov
>
> 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.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org