Bhat Bhat - 5 months ago 33
Java Question

Newline(%n) pattern for Log4j in Linux

I need a help to break the line and append the logs in new line in Java Web Application.

<PatternLayout pattern="%d{dd/MM/YYYY HH:mm:ss.SSS} [%t] %-5level %logger{36} %msg%n%n"/>

This is the pattern I used. I want to execute this in a Linux environment and
is not working instead logs are appended to the last line only

xav xav

Are you viewing the log file on Linux or on Windows? If the log file is written by Linux and viewed on Windows, the new line character will not create a new line on Windows using classical text editors, so all your logs will be on the same line.

You can either use \r\n in your Pattern instead of \n, or use another text editor in Windows (e.g. Notepad++) that handles Linux line separator (\n).