slimtoolkit/slim · error

unknown log-format

Error message

unknown log-format %q

What it means

setLogFormat maps the configured format string to a logrus formatter: 'text' uses a colorless TextFormatter, 'json' uses JSONFormatter. Any other value falls into the default branch and returns this error, which configureLogger surfaces as 'failed to set log format'.

Solutions

  1. Use exactly 'text' or 'json' (lowercase) for --log-format.
  2. If the value comes from an env var or template, validate/normalize it (strings.TrimSpace, lowercase) before passing it.
  3. Omit the flag entirely to keep the default formatter.

Example fix

// before
if format == "" { format = "JSON" } // wrong casing/empty
// after
format = strings.ToLower(strings.TrimSpace(format))
if format != "text" && format != "json" { format = "text" }
Defensive patterns

Strategy: validation

Validate before calling

func normalizeFormat(f string) string {
    f = strings.ToLower(strings.TrimSpace(f))
    if f != "text" && f != "json" { return "text" }
    return f
}

Type guard

func isUnknownFormatError(err error) bool {
    return err != nil && strings.Contains(err.Error(), "unknown log-format")
}

Try / catch

if err := Run(ctx); err != nil && strings.Contains(err.Error(), "unknown log-format") {
    fmt.Fprintf(os.Stderr, "unsupported format, must be text or json: %v\n", err)
    os.Exit(2)
}

Prevention

When it happens

Trigger: Passing a --log-format value other than 'text' or 'json' to the sensor, including empty strings from unset environment variables or templating mistakes.

Common situations: Users try formatter names from other logging libraries ('console', 'cli', 'logfmt'); CI injects an unsupported default; a typo such as 'jsn' or 'JSON' (case-sensitive switch).

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 slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/2a0a138bfd903c28. Report an issue: GitHub.

Appendix: source

Thrown at pkg/app/sensor/logger.go:52

		f, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
		if err != nil {
			return fmt.Errorf("failed to set log output destination to %q: %w", logFile, err)
		}

		log.SetOutput(f)
	}

	return nil
}

func setLogFormat(format string) error {
	switch format {
	case "text":
		log.SetFormatter(&log.TextFormatter{DisableColors: true})
	case "json":
		log.SetFormatter(&log.JSONFormatter{})
	default:
		return fmt.Errorf("unknown log-format %q", format)
	}

	return nil
}

func setLogLevel(enableDebug bool, levelName string) error {
	if enableDebug {
		log.SetLevel(log.DebugLevel)
		return nil
	}

	var logLevel log.Level

	switch levelName {
	case "trace":
		logLevel = log.TraceLevel
	case "debug":
		logLevel = log.DebugLevel

View on GitHub (pinned to 81940d17fa)