Snackoverflow
Snackoverflow

Reputation: 6271

Spring Boot logger new-line character

Is there a way to specify the new-line character used by the logger in Spring Boot?

Also, how can I find out which one it is using by default (\n or \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. However, I would like it to be \n always, whether I run the application on Windows or Linux.

Upvotes: 0

Views: 4233

Answers (2)

Snackoverflow
Snackoverflow

Reputation: 6271

After experimenting, I have found the solution I was looking for: simply use \n instead of %n in the logging pattern.

Is there a way to specify the new-line character used by the logger in Spring Boot?

If the logging pattern is explicitly specified in the application.yml or application.json configuration file, then yes. Otherwise, the specific configuration file for the logging framework should be changed (e.g. log4j2.xml for log4j2).

Also, how can I find out which one it is using by default (\n or \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, ...).

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, ...

Upvotes: 1

Andronicus
Andronicus

Reputation: 26026

How about using pattern, for example:

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

Upvotes: 2

Related Questions