crowdsecurity/crowdsec · error

invalid log_level in dsn: %w

Error message

invalid log_level in dsn: %w

What it means

ConfigureByDSN parses the optional `log_level` DSN parameter with log.ParseLevel (logrus). The value must be one of the accepted level names (panic, fatal, error, warn, info, debug, trace); anything else is wrapped with "invalid log_level in dsn".

Source

Thrown at pkg/acquisition/modules/victorialogs/config.go:188

		s.Config.MaxFailureDuration = duration
	} else {
		s.Config.MaxFailureDuration = 5 * time.Second // for OneShot mode it doesn't make sense to have longer duration
	}

	if limit := params.Get("limit"); limit != "" {
		limit, err := strconv.Atoi(limit)
		if err != nil {
			return fmt.Errorf("invalid limit in dsn: %w", err)
		}

		s.Config.Limit = limit
	}

	if logLevel := params.Get("log_level"); logLevel != "" {
		level, err := log.ParseLevel(logLevel)
		if err != nil {
			return fmt.Errorf("invalid log_level in dsn: %w", err)
		}

		s.Config.LogLevel = level
		s.logger.Logger.SetLevel(level)
	}

	s.Config.URL = fmt.Sprintf("%s://%s", scheme, u.Host)
	if u.User != nil {
		s.Config.Auth.Username = u.User.Username()
		s.Config.Auth.Password, _ = u.User.Password()
	}

	clientConfig := vlclient.Config{
		URL:      s.Config.URL,
		Headers:  s.Config.Headers,
		Limit:    s.Config.Limit,
		Query:    s.Config.Query,
		Since:    s.Config.Since,

View on GitHub (pinned to 909b515798)

Solutions

  1. Use one of: trace, debug, info, warn, error, fatal, panic (case-insensitive)
  2. Replace unsupported names like `notice`, `verbose`, or `warning` with the closest valid level (e.g. `warning` -> `warn`)
  3. Omit the parameter to keep the logger at its default level
  4. Check the wrapped logrus error, which lists the accepted values

Example fix

// before
url: victorialogs+http://127.0.0.1:8428?log_level=warning
// after
url: victorialogs+http://127.0.0.1:8428?log_level=warn
Defensive patterns

Strategy: validation

Validate before calling

const VALID = ["panic","fatal","error","warn","info","debug","trace"]
const lvl = p.searchParams.get("log_level")
if (lvl && !VALID.includes(lvl.toLowerCase())) {
  throw new Error(`invalid log_level: ${lvl}`)
}

Prevention

When it happens

Trigger: Providing `log_level=` in the DSN with an unrecognized level name, e.g. `log_level=verbose`, `log_level=WARNING`, `log_level=notice`.

Common situations: Users familiar with syslog severities (notice, warning spelled differently) or other logging frameworks using names logrus does not accept; matching is case-insensitive but names must be exact logrus levels.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/401916dd9d417dc1. Report an issue: GitHub.