简体   繁体   English

Spring Boot 记录器换行符

[英]Spring Boot logger new-line character

Is there a way to specify the new-line character used by the logger in Spring Boot?有没有办法指定 Spring Boot 中记录器使用的换行符?

Also, how can I find out which one it is using by default ( \\n or \\r\\n )?另外,我怎样才能找出它默认使用的是哪一个( \\n\\r\\n )?

If it is dependent on the system where the application is executed, how can I configure it to be non-system-dependent?如果它依赖于执行应用程序的系统,我如何将其配置为非系统依赖?

EDIT: When I examine the log file, I can see that the \\r\\n new-line is used.编辑:当我检查日志文件时,我可以看到使用了\\r\\n换行符。 However, I would like it to be \\n always, whether I run the application on Windows or Linux.但是,无论我在 Windows 还是 Linux 上运行应用程序,我都希望它始终为\\n

使用模式怎么样,例如:

logging.pattern.console=%-5level [%thread]: %message%n

After experimenting, I have found the solution I was looking for: simply use \\n instead of %n in the logging pattern .经过试验,我找到了我正在寻找的解决方案:只需在日志模式中使用\\n而不是%n

Is there a way to specify the new-line character used by the logger in Spring Boot?有没有办法指定 Spring Boot 中记录器使用的换行符?

If the logging pattern is explicitly specified in the application.yml or application.json configuration file, then yes.如果在application.ymlapplication.json配置文件中明确指定了日志记录模式,则是。 Otherwise, the specific configuration file for the logging framework should be changed (eg log4j2.xml for log4j2).否则,应该更改日志框架的特定配置文件(例如log4j2.xml的 log4j2.xml)。

Also, how can I find out which one it is using by default (\\n or \\r\\n)?另外,我怎样才能找出它默认使用的是哪一个(\\n 或 \\r\\n)?

By checking the logging output itself or logging pattern in the configuration.通过检查日志输出本身或配置中的日志模式。 And according to the pattern, check the logging framework's documentation.并根据模式,检查日志框架的文档。 It could be dependent on the underlying logging framework (logback, log4j2, ...).它可能依赖于底层日志框架(logback、log4j2、...)。

If it is dependent on the system where the application is executed, how can I configure it to be non-system-dependent?如果它依赖于执行应用程序的系统,我如何将其配置为非系统依赖?

By specifying the character explicitly in the pattern: \\n , \\r\\n , ...通过在模式中明确指定字符: \\n , \\r\\n , ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM