Thanks Mike, indeed. Sorry, I did not come across this ticket, may be I should have searched more within Jira before posting. Thanks for the quick reply.
On Wed, Mar 23, 2016 at 1:33 AM Mike Calmus <[email protected]> wrote: > 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 <[email protected]> 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 > >
