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