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?
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With