PraveenG
PraveenG

Reputation: 35

How to remove new line from all application logs using logback in spring boot

I am trying to remove all white spaces and new lines from the application logs.Is there any way I can remove all next lines from the appending logs using logback pattern?

Upvotes: 3

Views: 7144

Answers (1)

xav
xav

Reputation: 5608

Have you tried with %replace? For example:

<pattern>%d [%thread] %level %logger %replace(%msg){'[\s\n\r]',''}%n</pattern>

The above pattern will remove all spaces and new lines contained in the log entry message.

You can also remove spaces and new lines from multiple log entry fields like this:

<pattern>%d [%thread] %level %logger %replace(%logger %msg){'[\s\n\r]',''}%n</pattern>

See https://logback.qos.ch/manual/layouts.html#replace

Also, to remove new lines from stacktraces, please see How do I remove newline from Java stacktraces in logback?

Upvotes: 7

Related Questions