slackhq/nebula · error

unknown log format `%s`. possible formats: %s

Error message

unknown log format `%s`. possible formats: %s

What it means

SetFormat validates the requested log format against the supported set ('text' and 'json') and returns this error for anything else. It is an input validation error on the Handler's format configuration.

Source

Thrown at logging/logger.go:143

// SetLevel updates the effective log level. Propagates to every derived
// logger via the shared LevelVar.
func (h *Handler) SetLevel(level slog.Level) { h.root.level.Set(level) }

// GetLevel reports the current log level.
func (h *Handler) GetLevel() slog.Level { return h.root.level.Level() }

// SetFormat flips the output format atomically. Valid formats are "text"
// and "json". Every derived logger sees the new format on its next Handle
// call; no rebuild or registration is required.
func (h *Handler) SetFormat(format string) error {
	switch format {
	case "text":
		h.root.jsonMode.Store(false)
	case "json":
		h.root.jsonMode.Store(true)
	default:
		return fmt.Errorf("unknown log format `%s`. possible formats: %s", format, []string{"text", "json"})
	}
	return nil
}

// GetFormat reports the currently selected format name.
func (h *Handler) GetFormat() string {
	if h.root.jsonMode.Load() {
		return "json"
	}
	return "text"
}

// SetDisableTimestamp toggles whether Handle zeroes r.Time before
// dispatching (slog's builtin text/json handlers skip emitting the time
// attribute on a zero time).
func (h *Handler) SetDisableTimestamp(v bool) { h.root.disableTimestamp.Store(v) }

// ApplyConfig reads logging.level, logging.format, and (optionally)

View on GitHub (pinned to dd8f660c0a)

Solutions

  1. Pass exactly "text" or "json" to SetFormat
  2. Normalize/trim the format string before calling SetFormat
  3. Default to "text" when the config value is absent

Example fix

// before
err := h.SetFormat("logfmt")
// after
format := strings.ToLower(strings.TrimSpace(cfg.Format))
if format != "json" {
    format = "text"
}
err := h.SetFormat(format)
Defensive patterns

Strategy: validation

Validate before calling

switch strings.ToLower(strings.TrimSpace(format)) {
case "text", "json", "":
    // ok
default:
    return fmt.Errorf("unsupported log format %q", format)
}

Prevention

When it happens

Trigger: Calling Handler.SetFormat with any string other than "text" or "json", e.g. "logfmt", "TEXT", or empty string.

Common situations: Typo in config 'logging.format'; case sensitivity; copying formats from another logging library that supports logfmt/syslog.

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 slackhq/nebula@dd8f660c0a (2026-09-03). Data as JSON: /api/errors/1b37e23dfb15a64f. Report an issue: GitHub.