logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Calmus <m...@calmus.org.INVALID>
Subject Re: Header does not end with a new line in Console appender
Date Tue, 22 Mar 2016 20:03:41 GMT
This is included as an improvement in Log4j2 2.6:

https://issues.apache.org/jira/browse/LOG4J2-1237


> On Mar 22, 2016, at 2:30 PM, Kamal Mettananda <lkamal@gmail.com> wrote:
> 
> Hi all
> 
> This is my first email, so please raise if I have not correctly understood
> the usage of the header attribute.
> 
> When I add a text to the header attribute of PatternLayout inside Console
> appender, the header will not end with a new line hence the first log line
> will also be using the same line as the header line; but this is not the
> case for footer attribute.
> 
> Example output:
> My Header in Log2016-03-22 23:23:48,487 [main] INFO
> org.logging.learn.log4j.Main - some log1
> 2016-03-22 23:23:48,487 [main] INFO  org.logging.learn.log4j.Main - some
> log2
> Footer
> 
> Below is the sample of my log4j2.xml
> 
> <Configuration status="WARN">
>  <Appenders>
>    <Console name="Console" target="SYSTEM_OUT">
>      <PatternLayout pattern="%d [%t] %-5level %logger - %msg%n" header="My
> Header in Log" footer="Footer"/>
>    </Console>
>  </Appenders>
>  <Loggers>
>    <Root level="info">
>      <AppenderRef ref="Console"/>
>    </Root>
>  </Loggers>
> </Configuration>
> 
> May be there is a way to enable a new line via for the header?
> 
> When I looked at the
> code, org.apache.logging.log4j.core.appender.OutputStreamManager actually
> does not append a new line after the header; may be a simple fix can be
> made there? (Not exactly sure whether I was looking at the correct
> location, please point out if I am incorrect).
> 
>        if (writeHeader && layout != null) {
>            final byte[] header = layout.getHeader();
>            if (header != null) {
>                try {
>                    this.os.write(header, 0, header.length);
>                } catch (final IOException e) {
>                    logError("unable to write header", e);
>                }
>            }
>        }
> 
> Thanks


Mime
View raw message