40

I want to add a blank line after my LOG statement in order to make my logs more separated and readable.

How do I do this?

Current statement:

 LOGGER.info("Person's name is  {} .", person.getName());

Note that I don't want to do this after every statement, just for certain statements.

java123999
  • 6,974
  • 36
  • 77
  • 121
  • **Add #\n instead of \n** https://stackoverflow.com/questions/15254304/how-do-you-insert-a-newline-in-message-body-of-mule-logger-component – user8642884 Sep 20 '17 at 16:07

2 Answers2

49

Simply add \n at the end of the string to log.

LOGGER.info("Person's name is  {} .\n", person.getName());

If you are in a windows environment use \r\n


To get the right value of new line if you don't know the end operating system of your application you can use the property line.separator

String lineSeparator = System.getProperty("line.separator");
LOGGER.info("Person's name is  {} .{}", person.getName(), lineSeparator);
VaL
  • 1,128
  • 15
  • 29
Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56
36

dont use \n character, but ask the System what is the newline propery. could be different in linuxor windows or..

so use

System.lineSeparator();

or before java 7 use

System.getProperty("line.separator");
lordkain
  • 3,061
  • 1
  • 13
  • 18