Print --http-debug logs into file & print all api responses in a file

Hi,

when ever I run --http-debug from terminal all the request related data in the terminal which is quite difficult to track so want to print it in a file how can I do that? similarly I have more than 80 api’s, for which I want to print response body in same file how can I do that? Tried multiple ways but not able to do it.
Also apart from --http-debug= full can set trace or warn debugging levels?
Please help

You cannot open a file and write to it from inside of a k6 script, but you can redirect the k6 stderr output to a file like this:

k6 run --logformat=raw --http-debug=full github.com/loadimpact/k6/samples/http_get.js 2> http_debug.txt

Alternatively, you can find other approaches to debugging HTTP requests in Dump all outgoing requests in json?, including using console.warn() and such, though as you can see from that thread, there are caveats.

As of version 0.28, you can use --logformat=json (combined with ned’s command line above) to get a nice machine-usable log file. However it’s not possible to reliably map requests to their responses, nor be able to tell which requests came from which VUs (or from setup/teardown)…there is an open PR here Add additional log information to http-debug · Issue #1645 · grafana/k6 · GitHub which adds that capability, but has not been merged yet…

Thanks, it worked …