user3679728
user3679728

Reputation: 35

new line is not coming in log4j

I have added logging in my project but i have two issues.First is that new lines are not coming between various log enteries. And second is that I am not able to change the log location to relative path also. Here is my log4j.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<File name="A1" fileName="C:\log\A1.log" append="false">
  <PatternLayout pattern="%t %-5p %c{2} - %m%n"/>
</File>
<Console name="STDOUT" target="SYSTEM_OUT">
  <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.log4j.xml" level="debug">
  <AppenderRef ref="A1"/>
</Logger>
<Root level="debug">
  <AppenderRef ref="A1"/>
</Root>
</Loggers>
</Configuration>

Upvotes: 0

Views: 3084

Answers (1)

Remko Popma
Remko Popma

Reputation: 36754

Your configuration looks correct: the pattern for both appenders ends in %n, which should make every message appear on separate lines. If you want an empty line between two log entries, you can try using a pattern that ends in %n%n.

If your output looks like all messages are concatenated without newlines, like this:

main INFO my.class - message1main INFO my.class - message2main INFO my.class - message3

Then it is most likely that your application is actually using a different configuration than the one shown in your question. Could it be that one of your jars contains an old log4j2.xml config file?

Upvotes: 1

Related Questions