hibiken/asynq · error

asynq: unsupported log level

Error message

asynq: unsupported log level %q

What it means

This error is returned by SetLogLevel (via the internal toLogLevel parser) in asynq when the supplied log level string does not match one of the recognized levels (debug, info, warn, error, fatal). The library validates the string strictly case-insensitively against its enum and refuses any unknown value. It is a guard against silently running with an undefined logging configuration.

Solutions

  1. Change the log level string to one of: debug, info, warn, error, fatal.
  2. Validate the configured value against the allowed set before calling SetLogLevel.
  3. Lowercase and trim the input string if it may come from env/config with casing or whitespace.
  4. If using SetLogLevel, prefer asynq.LogLevel(...) or the built-in constants to avoid string typing.

Example fix

// before
srv.SetLogLevel("WARNING")
// after
srv.SetLogLevel("warn") // allowed: "debug","info","warn","error","fatal"
Defensive patterns

Strategy: validation

Validate before calling

var validLevels = map[string]bool{"debug":true,"info":true,"warn":true,"error":true,"fatal":true}
if !validLevels[strings.ToLower(strings.TrimSpace(cfg.LogLevel))] {
    return fmt.Errorf("invalid log level %q; must be one of debug,info,warn,error,fatal", cfg.LogLevel)
}
srv.SetLogLevel(strings.ToLower(cfg.LogLevel))

Try / catch

if err := srv.SetLogLevel(level); err != nil {
    log.Fatalf("bad log level: %v", err)
}

Prevention

When it happens

Trigger: Calling srv.SetLogLevel("verbose"), SetLogLevel("WARNING"), or any string outside {debug, info, warn, error, fatal}; passing a log level read from an environment variable or config file that asynq does not recognize.

Common situations: Operators configure ASYNQ_LOG_LEVEL or a YAML config with values like "trace", "warning", or "none"; typos in deployment configs; migrating from another logging library whose level names differ.

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 hibiken/asynq@d135f1439b (2026-09-07). Data as JSON: /api/errors/d7415565fe697008. Report an issue: GitHub.

Appendix: source

Thrown at server.go:378

	}
	panic(fmt.Sprintf("asynq: unexpected log level: %v", *l))
}

// Set is part of the flag.Value interface.
func (l *LogLevel) Set(val string) error {
	switch strings.ToLower(val) {
	case "debug":
		*l = DebugLevel
	case "info":
		*l = InfoLevel
	case "warn", "warning":
		*l = WarnLevel
	case "error":
		*l = ErrorLevel
	case "fatal":
		*l = FatalLevel
	default:
		return fmt.Errorf("asynq: unsupported log level %q", val)
	}
	return nil
}

func toInternalLogLevel(l LogLevel) log.Level {
	switch l {
	case DebugLevel:
		return log.DebugLevel
	case InfoLevel:
		return log.InfoLevel
	case WarnLevel:
		return log.WarnLevel
	case ErrorLevel:
		return log.ErrorLevel
	case FatalLevel:
		return log.FatalLevel
	}
	panic(fmt.Sprintf("asynq: unexpected log level: %v", l))

View on GitHub (pinned to d135f1439b)