Stack trace new lines escaping / formatting


my log statements sometimes has a stack trace.
Like this: “stacktrace”: “java.lang.RuntimeException: This is an error\n\tat io.myapp.LoggerTest.main(\n”.

It has \n symbols, but by default it is displayed as one line, without carriage return.

Grafana shows me a message “Your logs might have incorrectly escaped content” and offers to escape new lines.

When I agree, then my stack trace displayed very nice, with carriage return:
“stacktrace”:"java.lang.RuntimeException: This is an error
at io.myapp.LoggerTest.main(

The same situation with nested json objects.

So my question is following: how should I format my logs to have new lines escaped correctly?
What stages to use?

I have checked the internet, this community topics and this question is still not resolved.
So what symbols should be used to correctly escape new lines?

If you use “escape new lines” function and “prettify json” together - that breaks displaying of JSON.

This is important problem. PLEASE react.