Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too aggressive character escaping when using --log-format json #3691

Open
xresch opened this issue Apr 18, 2024 · 1 comment
Open

Too aggressive character escaping when using --log-format json #3691

xresch opened this issue Apr 18, 2024 · 1 comment
Assignees
Labels
bug evaluation needed proposal needs to be validated or tested before fully implementing it in k6 triage

Comments

@xresch
Copy link

xresch commented Apr 18, 2024

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

@olegbespalov
Copy link
Collaborator

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).

k6/cmd/root.go

Line 252 in 144209f

c.globalState.Logger.SetFormatter(&logrus.JSONFormatter{})

However, we (k6 maintainers) need to discuss this, keeping in mind possible implications and also keeping in mind that we have this #2958

I'll get back to you 👍

@olegbespalov olegbespalov added the evaluation needed proposal needs to be validated or tested before fully implementing it in k6 label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug evaluation needed proposal needs to be validated or tested before fully implementing it in k6 triage
Projects
None yet
Development

No branches or pull requests

2 participants