How do I add a line break / blank line after my LOG statement?

java123999 picture java123999 · Feb 29, 2016 · Viewed 31.7k times · Source

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.

Answer

Davide Lorenzo MARINO picture Davide Lorenzo MARINO · Feb 29, 2016

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);