lukas84
lukas84

Reputation: 425

log4j writes blank lines in console

I have the following log4j configuration:

<appender name="MYCONSOLE" class="org.apache.log4j.ConsoleAppender">
  <param name="Threshold" value="INFO"/>
  <param name="Target" value="System.out"/>
  <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d{ISO8601}|%-5p|MYAPP|%t|%C{1}.%M(%L)|%m%n"/>
  </layout>
</appender>

<appender name="MYFILE" class="org.apache.log4j.DailyRollingFileAppender">
  <param name="File" value="${jboss.server.log.dir}/myapp.log"/>
  <param name="Append" value="true"/>
  <param name="DatePattern" value="'.'yyyy-MM-dd"/>

  <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d{ISO8601}|%-5p|MYAPP|%t|%C{1}.%M(%L)|%m%n"/>
  </layout>
</appender>

In the Eclipse console, every log line produced by this configuration is followed by a completely blank line:

12:46:27,289 INFO  [stdout] 2017-01-25 12:46:27,289|INFO|MYAPP|something

12:46:27,289 INFO  [stdout] 2017-01-25 12:46:27,289|INFO|MYAPP|something else

This happens only with logs generated by MYCONSOLE, all other logs (such as the internal JBoss's ones) don't have blank lines. Also, in the MYFILE log file, the logs are the same but the blank lines are not there.

What could be the reason?

Upvotes: 3

Views: 1809

Answers (2)

Basapuram Kumar
Basapuram Kumar

Reputation: 179

Getting same to me when I use consoleAppader for audit logger

log4j.appender.audit=org.apache.log4j.ConsoleAppender
log4j.appender.audit.layout=org.apache.log4j.PatternLayout
log4j.appender.audit.Target=System.out
log4j.appender.audit.ConversionPattern=%d{ISO8601}|%t|%m%n

The logs dumping on console are empty/blank lines.

If I remove I can get rid of empty lines, I am missing actual data too. Would appreciate any pointers

Upvotes: 0

lukas84
lukas84

Reputation: 425

I was able to get rid of the extra lines by using \n instead of %n.

The reason of the strange behaviour of %n is still not clear to me.

Upvotes: 7

Related Questions