我想在
LOG
语句后添加一个空行,以使我的日志更加分离和可读。
我该怎么做?
当前声明:
LOGGER.info("Person's name is {} .", person.getName());
请注意,我不想在 every 语句之后执行此操作,只是针对某些语句。
只需在要记录的字符串末尾添加
\n
即可。
LOGGER.info("Person's name is {} .\n", person.getName());
如果您在 Windows 环境中使用
\r\n
操作系统独立解决方案:
如果您不知道应用程序的最终操作系统,要获得正确的换行值,可以使用
System.lineSeperator()
或与 < JDK 7 System.getProperty("line.separator")
LOGGER.info("Person's name is {} .{}", person.getName(), System.lineSeparator());
不要使用
\n
字符,但询问系统换行符属性是什么。在 Linux 或 Windows 中可能会有所不同,或者..
所以使用
System.lineSeparator();
或在java 7使用之前
System.getProperty("line.separator");