java123999
java123999

Reputation: 7404

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

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.

Upvotes: 42

Views: 75977

Answers (2)

Davide Lorenzo MARINO
Davide Lorenzo MARINO

Reputation: 26946

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


OS independet solution:

To get the right value of new line if you don't know the end operating system of your application, you can use System.lineSeperator() or with < JDK 7 System.getProperty("line.separator")

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

Upvotes: 52

lordkain
lordkain

Reputation: 3109

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

Upvotes: 38

Related Questions