I’m running load tests using k6, and the console output is very verbose. I want to reduce it so I only see warnings or errors.
Is there a way to configure the log level in k6? For example, I tried using console.log in my script like this:
import http from 'k6/http';
import { check } from 'k6';
export default function () {
    let res = http.get('https://test.k6.io');
    console.log(`Status: ${res.status}`); // How can I control the log level of this output?
    check(res, { 'status is 200': (r) => r.status === 200 });
}
I want to know if there’s a built-in way to filter or set log levels for output messages.
             
            
              
              
              
            
           
          
            
            
              In my experience, the best way to control verbosity in k6 is via environment variables when running the test. k6 supports log-level filtering for internal logging.
For example:
K6_LOG_LEVEL=warning k6 run script.js
This reduces the output to only warnings and errors. You can also use K6_LOG_LEVEL=error for just errors, or info/debug for more verbose output.
Keep in mind that console.log calls in your script always print to stdout, so these env variables don’t filter console.log, only internal k6 logs.
To get started with K6 follow this documentation on K6 testing and get detail insights.
             
            
              
              
              
            
           
          
            
            
              I ran into the same issue: console.log always prints, which can clutter CI logs.
One trick I use is to create a wrapper function:
const logLevel = 'warning'; // 'info', 'warning', 'error'
function log(msg, level = 'info') {
    const levels = { debug: 0, info: 1, warning: 2, error: 3 };
    if (levels[level] >= levels[logLevel]) {
        console.log(`[${level.toUpperCase()}] ${msg}`);
    }
}
export default function () {
    log('This is info', 'info');
    log('This is a warning', 'warning');
}
This gives you full control over which messages appear based on your defined log level.
             
            
              
              
              
            
           
          
            
            
              For CI pipelines, I often don’t need console.log messages at all. In those cases, I either comment them out or redirect stdout/stderr when invoking k6:
k6 run script.js > /dev/null 2>&1
Then only k6 internal warnings/errors will show if you combine it with K6_LOG_LEVEL=warning. This keeps your CI logs clean without changing the script.