Log4J does not add new lines between log entries

I am just starting with log4j. I have no problem reading my properties file and actually logging events, but it seems to add everything to the end of the same line. My properties file is as follows:

# A1 is set to be a ConsoleAppender. log4j.appender.A1=org.apache.log4j.ConsoleAppender # A2 is set to be a ConsoleAppender. log4j.appender.A2=org.apache.log4j.FileAppender # A1 uses PatternLayout. log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n # A2 uses PatternLayout. log4j.appender.A2.layout=org.apache.log4j.PatternLayout log4j.appender.A2.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n% log4j.appender.A2.file=grocerylister.log 

The above has been modified from the example in log4j "Complete Guide". I fruitlessly looked through the book and Google to get a list of what all options mean, but to no avail.

I am using log4j version 1.2.15 with Java 6. What can I do to get each entry on a separate line and where can I find a list of what all the parameters are and what they do?

+4
source share
2 answers

Replace

 log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 

from

 log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 

The same for A2 + removes % after n %m%n%m%n

Basically you seem to have a newline after the character - in your ConversionPattern lines. This explains why the newline is not output ( %n → displays the platform of the dependent newline character)

Btw. if you want to know what options mean

javadoc: PatternLayout

+10
source

Are those %m%n on the same line as the rest? If not, this will explain it.

Oh, and for the second application, you have% after %n . That doesn't look right either.

+4
source

All Articles