Display stacktrace/multiline label in grafana log browser

Hello,
I’m trying to display properly java stacktrace in grafana log/loki explorer.

What I do :
My logs are JSON line like this :

{"time":"2021-08-19T14:07:56.802Z","level":"ERROR","message":"Bla bla bla \n More Bla bla", "exception":{"class":"some.java.class","message":"This is an error","stacktrace":"stack line 1\n\t at stack line 2\n\t at stack line 3\n\t at stack line 4\n\t ..."}}

My loki query is like this :
{container="api"} | json | line_format "{{.message}}"

What I have :

  1. the json is correctly returned by the server and contains all the \n
  2. the json is parsed properly and I have the exra labels “time”, “level”, “message”, “execption_message” and “exception_stacktrace” parsed properly.
  3. but all the \n in message, exception_stacktrace are removed and ignored in display.
  4. when I toggle “Wrap lines”, it only wrap long lines and doesn’t care about my newlines
  5. as a consequence, my stack trace is unreadable and appears like this : "stack line 1 at stack line 2 at stack line 3 at stack line 4 ..." with wraps when en of screen is reached.

What I expect:

  • I want the \n to be replaced by newlines so that the stacktraces and messages apear as they are meant to when linewrap is unabled.

I read there is a “proper way” to escape newline but I didn’t find any documentation on this.
Can one help ?
Thanks

I’m running

  • grafana 8.1.1, Loki 2.
  • Springboot 2.2.10
  • Log4J with JsonTemplateLayout for log formating

I found adding white-space: pre-wrap to wordBreakAll css fixes the formating and all \n appears as new line as expected.
I also found there is a wrapLogMessage property that is suppose to set the css above.
however, I found nowhere this wrapLogMessage can be set to true.
any hint ?

Topic moved to “Grafana Loki” category.