-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
output format for errors changes to structured log when running k6 as a subprocess #3744
Comments
Hi @pablochacin, Looking at the k6 codebase, that's the expected behavior, because it explicitly sets one output format or the other depending whether k6 is executed in a terminal or not. I don't have enough historical context to fully assert if that's intentionally (or not), and whether we want to actually change that behavior, thus consider it a bug, or just the expected behavior. Especially considering that, if this behavior have been like this for years, it would represent a breaking change (what if anyone is doing what you're trying but relying on the current behavior?) That said, the only recommendation that comes to my mind is to "fake" that behavior, so cmd := exec.Command("k6", "run", "script.js")
// Start the command with a pseudo-terminal
ptmx, _ := pty.Start(cmd)
// Copy the output to the buffer
outBuff := bytes.NewBuffer(nil)
_, _ = io.Copy(outBuff, ptmx)
fmt.Println(outBuff.String()) Note that this snippet is just to give you an idea, so I'm intentionally skipping error handling and all that. Thanks! 🙇🏻 |
I'm wondering, if there's any other way to bypass that, or if the change we could make is to leave the default behavior as-is but add a mechanism to bypass/force that behavior by configuration cc/ @mstoykov |
This seems to be more of a logrus thing. Where if it detects TTY it will change how it outputs. And apparently having colours or not changes more than just ... colors. See sirupsen/logrus#1194 as well as search the docs for TextFormatter (sorry can't link directly any particular place). Given that this has been like this for a while and #2958 I don't feel like we should try to "fix" this. Also I am not certain what the fix will be. I would also expect anything running k6 as a subprocess to prefer the |
That depends on the use case. In our case, we are capturing the output and displaying it if we find some error, and the log format obscures this output, as shown in the example
Given that #2958 has been open for quite a while, I expect we find some fix for this issue in the meantime.
From Logrus documentation:
|
Brief summary
When running k6 as a subprocess (from a go program) and capturing the stdout and stderr in a buffer, the format of error messages changes to a structured log format.
k6 version
v0.50.0
OS
windows
Docker version and image (if applicable)
No response
Steps to reproduce the problem
Create an empty file named
script.js
Run the following go program:
Expected behaviour
The same output that is generated when running the
script.js
file withk6
in the console:Actual behaviour
The output has a structured log format:
The text was updated successfully, but these errors were encountered: