Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 660
PraveenG Avatar asked Nov 18 '25 16:11

PraveenG


1 Answers

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?

like image 83
xav Avatar answered Nov 21 '25 06:11

xav