Reputation: 303
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 %n
is not working instead logs are appended to the last line only
Upvotes: 4
Views: 13631
Reputation: 303
I retain the pattern string for log as
<PatternLayout pattern="%msg"/>
and modified the LogManagement.java
private static final Logger LOGGER_OBJECT = LogManager.getLogger(LogManagement.class);
private static final String STRING_DATE_FORMAT = "dd MMM yyyy HH:mm"; //Date & Time format
private static final SimpleDateFormat SIMPLE_DATE_FORMAT_PATTERN = new SimpleDateFormat(STRING_DATE_FORMAT); //Simple format conversion
code at info function
LOGGER_OBJECT.info("\r\n"); //New Line
LOGGER_OBJECT.info("Log Type\t: INFO"); //Log Type
LOGGER_OBJECT.info("\r\n");
LOGGER_OBJECT.info("Date & Time\t: "+SIMPLE_DATE_FORMAT_PATTERN.format(new Date()));//Current Date & Time
LOGGER_OBJECT.info("\r\n");
This works fine when I log the data in Linux and view in Windows platform
Upvotes: 0
Reputation: 5608
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
).
Upvotes: 7