crowdsecurity/crowdsec · error

invalid log_level in dsn: %w

Error message

invalid log_level in dsn: %w

What it means

ConfigureByDSN validates the optional 'log_level' DSN parameter with log.ParseLevel (logrus). Any string that is not one of the recognized levels (panic, fatal, error, warn, info, debug, trace) causes this error.

Source

Thrown at pkg/acquisition/modules/loki/config.go:201

	} else {
		l.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)
		}

		l.Config.Limit = limit
	} else {
		l.Config.Limit = 5000 // max limit allowed by loki
	}

	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)
		}

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

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

		l.Config.NoReadyCheck = noReadyCheck
	}

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

View on GitHub (pinned to 909b515798)

Solutions

  1. Use a valid logrus level: trace, debug, info, warn, error, fatal or panic
  2. Use lowercase spellings; logrus levels are case-sensitive at parse time
  3. Remove the log_level parameter to keep the default level

Example fix

// before
loki://localhost:3100/?log_level=WARNING
// after
loki://localhost:3100/?log_level=warn
Defensive patterns

Strategy: validation

Validate before calling

if lvl := params.Get("log_level"); lvl != "" {
    if _, err := log.ParseLevel(lvl); err != nil {
        return fmt.Errorf("log_level must be one of panic,fatal,error,warn,info,debug,trace")
    }
}

Prevention

When it happens

Trigger: A DSN like loki://host:3100/?log_level=verbose or log_level=WARNING is configured.

Common situations: Using non-logrus level names (uppercase 'WARNING', 'verbose') copied from other logging libraries.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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