javaloggingslf4jline-breaks

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.


Solution

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