Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Line separator (\u2028) into Logback pattern

Tried to add custom Logback pattern in order to log Exception stacktraces into a single line (where new line character is replaced with unicode Line separator \u2028), as:

%date{"yyyy-MM-dd'T'HH:mm:ss.SSSZ", UTC} %5p %t %c{5}:%L [log_framework=logback;app_name=${APP_NAME};app_version=${APP_VERSION};instance_id=${CF_INSTANCE_INDEX}] %m MULTIEXCEPTION %replace(%xException){'\n','\u2028'}%nopex%n 

Note: See spring-config.xml config file in Github

In the console, \n is replaced, the Exception stacktrace is in one line but, instead with "Line separator" character (\u2028), \n is replaced with the string "u2028".

If I try to log directly this "Line separator" character (via Logback, as log message) - it is printed in the console correctly.

What could be the problem?

like image 273
Drazen Nikolic Avatar asked Sep 05 '26 20:09

Drazen Nikolic


1 Answers

I've managed to do this by entering the "Line separator" unicode character (
) directly:

%date{"yyyy-MM-dd'T'HH:mm:ss.SSSZ", UTC} %5p %t %c{5}:%L [log_framework=logback;app_name=${APP_NAME};app_version=${APP_VERSION};instance_id=${CF_INSTANCE_INDEX}] %m MULTIEXCEPTION %replace(%xException){'\n','
'}%nopex%n 

Note: You can also manage to make Exception stacktraces "single-lined" in Spring Boot application by adding next application property:

logging.exception-conversion-word: "%replace(%xException){'\\n','\u2028'}%nopex"
like image 194
Drazen Nikolic Avatar answered Sep 07 '26 17:09

Drazen Nikolic