Logging messages can help you debug load tests.
The k6 API supports the following console-logging methods:
Note: console.debug() will log output only when you run k6 with the -v/--verbose flag.
Logs can help you troubleshoot your test execution.
Tip: Debug locally first
When your script is ready, execute the test on the k6 Cloud with the k6 cloud command.
With the Logs Tab, you can view, filter, and query log messages in the Cloud Results page.
Beyond reading log messages, you can also use the log panel to find contextual information, such as:
- The log date in the local time zone
- The load zone. The geographic zone where the load generator is.
- The instance ID. The numerical ID of the load generator taking part in the test.
Refer to how the k6 Cloud injects environment variables for further information about the load zone and instance ID.
To filter messages by severity:
- Use the Log level dropdown.
- Info: console.log and console.info.
- Debug: console.debug.
- Warning: console.warning.
- Error: console.error.
The load-zone filter displays only when your test runs in more than one load zone.
After a test run finishes, you can start querying the logs. The query outputs messages that contain the string you've specified in the input.
While logs help you debug, they should not replace k6 API functions. It is often an anti-pattern to use logs in the following ways:
- Track the status of a condition. Instead, use Checks to assert these conditions.
- Track a variable value during the test execution. Instead, use the Trend metric.
However, you also should not rely on logging to interpret or analyze the performance of your system.
For this reason, the cloud logs have some limitations:
- The logs are deleted three days after the test execution.
- The number of log lines is limited to 10 messages per second per server. If this limit is exceeded, k6 shows a warning with the number of discarded log lines.
k6 aims to have a consistent experience when running local and cloud tests.
When running cloud tests with the CLI (k6 cloud), k6 prints cloud logs on standard output, like it would with your local tests.
To silence logs from printing on the terminal, add the --show-logs=false flag.