How to remove or replace newline from log messages log4j
问题 I am using below conversion pattern log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS Z} [%t] %-5p %c- %m%n but I want to remove new line characters. I have tried using %replace(%ex){'[\r\n]+', '\\n'}%nopex%n but it's not working %replace is not working. it only reading %r and then eplace 回答1: It seems you were not using the right syntax of the %replace - see Log4j Layouts for the right one. Using the right syntax, you could remove all the newlines using the following