grafana/k6 · error

invalid log level , should be one of: panic, fatal, error…

Error message

invalid log level %q, should be one of: panic, fatal, error, warn, warning, info, debug, trace

What it means

When the browser module builds its extension-wide logger at launch, it reads the K6_BROWSER_LOG environment variable and calls logger.SetLevel with it. If the value is not one of panic, fatal, error, warn, warning, info, debug or trace, SetLevel rejects it and launch fails with this message. It is a pure configuration-validation error: nothing is wrong with the browser, only the env value.

Solutions

  1. Set K6_BROWSER_LOG to one of the listed levels, e.g. K6_BROWSER_LOG=debug
  2. Unset K6_BROWSER_LOG entirely if browser-specific debug logging is not needed
  3. Use k6's own --loglevel flag for k6-wide log level instead of this browser-specific variable
  4. Check the CI/compose environment for whitespace or quotes around the value

Example fix

# before
K6_BROWSER_LOG=verbose k6 run script.js

# after
K6_BROWSER_LOG=debug k6 run script.js
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
# Fail fast before k6 runs if K6_BROWSER_LOG is invalid
case "$K6_BROWSER_LOG" in
  ""|panic|fatal|error|warn|warning|info|debug|trace) ;;
  *) echo "K6_BROWSER_LOG='$K6_BROWSER_LOG' invalid; use panic|fatal|error|warn|warning|info|debug|trace"; exit 2;;
esac
k6 run script.js

Prevention

When it happens

Trigger: Setting K6_BROWSER_LOG to an unsupported value such as "verbose", "all", "off", "LOG_DEBUG", or a value with stray whitespace/quotes (common in CI YAML). The check runs as soon as the browser is first used in the script.

Common situations: Copying Playwright-style DEBUG env config into k6; leftover K6_BROWSER_LOG from other tooling in CI; confusing it with k6's own --loglevel flag, which accepts a different set of values.

Related errors


AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18). Data as JSON: /api/errors/33c57505e61af6a1. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/chromium/browser_type.go:558

		hostResolver = append(hostResolver, fmt.Sprintf("MAP %s %s", k, v))
	}
	if len(hostResolver) > 0 {
		sort.Strings(hostResolver)
		flags["host-resolver-rules"] = strings.Join(hostResolver, ",")
	}

	return nil
}

// makeLogger makes and returns an extension wide logger.
func makeLogger(ctx context.Context, envLookup env.LookupFunc) (*log.Logger, error) {
	var (
		k6Logger = k6ext.GetVU(ctx).State().Logger
		logger   = log.New(k6Logger, common.GetIterationID(ctx))
	)
	if el, ok := envLookup(env.LogLevel); ok {
		if logger.SetLevel(el) != nil {
			return nil, fmt.Errorf(
				"invalid log level %q, should be one of: panic, fatal, error, warn, warning, info, debug, trace",
				el,
			)
		}
	}
	if _, ok := envLookup(env.LogCaller); ok {
		logger.ReportCaller()
	}

	return logger, nil
}

View on GitHub (pinned to 8d06114777)