k6
k6 copied to clipboard
Too aggressive character escaping when using --log-format json
Brief summary
Situation:
Logs are used for analyzing and debugging our scripts and HTTP responses are therefore written to the log.
The log is very hard to read as html data is not human readable anymore when using --log-format json
.
Data:
- To analyze if checks are working properly, which are verifying if a response body contains a certain string, it is crucial to be able to output the html response in a readable way.
- The K6 scripts are executed on a Monitoring Platform (Exense Step), which needs the
--log-format json
to be able to parse the outputs. So we cannot use--log-format raw
. - The json encoding of strings seems much to aggressive for logging outputs. The only characters you must escape are
\
,"
and control codes (anything less than U+0020). Other characters like "<" and ">" as encoded as well to "\uxxxx" style, what blows up the whole output and makes it unreadable for ze human eyes.
Expected Behavior: Console logs are still readable for a human with IT background.
Reproduction of issue: K6 Script:
export default function () {
console.log("<test>")
}
Output with --log-format json
;
PS C:\tmp> k6 run .\reproducer.js --log-format json
{"level":"info","msg":"\u003ctest\u003e","source":"console","time":"2024-04-17T09:24:38+02:00"}
Output with --log-format raw
;
PS C:\tmp> k6 run .\reproducer.js --log-format raw
<test>
k6 version
v0.48.0
OS
windows
Docker version and image (if applicable)
n/a
Steps to reproduce the problem
see description
Expected behaviour
see description
Actual behaviour
see description
Hi @xresch !
Thanks for reporting this.
The issue comes from our logging library (github.com/sirupsen/logrus
), which escapes HTML by default (DisableHTMLEscape: false
, default is value).
https://github.com/grafana/k6/blob/144209f37be8c2dbe1bcb5cdc14f965525543b8b/cmd/root.go#L252
However, we (k6 maintainers) need to discuss this, keeping in mind possible implications and also keeping in mind that we have this https://github.com/grafana/k6/issues/2958
I'll get back to you :+1: