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 :
- the json is correctly returned by the server and contains all the \n
- the json is parsed properly and I have the exra labels “time”, “level”, “message”, “execption_message” and “exception_stacktrace” parsed properly.
- but all the
\n
in message, exception_stacktrace are removed and ignored in display. - when I toggle “Wrap lines”, it only wrap long lines and doesn’t care about my newlines
- 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