slimtoolkit/slim · error

failed to set log format: %v

Error message

failed to set log format: %v

What it means

configureLogger applies the log format via setLogFormat, which only accepts 'text' or 'json'. Any other --log-format value hits the default branch and returns this error, aborting sensor startup.

Source

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

	"fmt"
	"os"

	log "github.com/sirupsen/logrus"
	"github.com/slimtoolkit/slim/pkg/util/fsutil"
)

func configureLogger(
	enableDebug bool,
	levelName string,
	format string,
	logFile string,
) error {
	if err := setLogLevel(enableDebug, levelName); err != nil {
		return fmt.Errorf("failed to set log-level: %v", err)
	}

	if err := setLogFormat(format); err != nil {
		return fmt.Errorf("failed to set log format: %v", err)
	}

	if len(logFile) > 0 {
		// This touch is not ideal - need to understand how to merge this logic with artifacts.PrepareEnv().
		if err := fsutil.Touch(logFile); err != nil {
			return fmt.Errorf("failed to set log output destination to %q, touch failed with: %v", logFile, err)
		}

		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
}

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Set --log-format to exactly 'json' or 'text'.
  2. If using templated config, ensure the variable resolves to one of the supported values and is non-empty.
  3. Remove the --log-format flag to use the library default instead of an unsupported value.

Example fix

// before
args: ["--log-format", "console"]
// after
args: ["--log-format", "json"]
Defensive patterns

Strategy: validation

Validate before calling

func validLogFormat(f string) bool {
    f = strings.ToLower(strings.TrimSpace(f))
    return f == "text" || f == "json"
}

Type guard

func isLogFormatError(err error) bool {
    return err != nil && strings.Contains(err.Error(), "failed to set log format")
}

Try / catch

if err := Run(ctx); err != nil && strings.Contains(err.Error(), "failed to set log format") {
    fmt.Fprintf(os.Stderr, "bad --log-format, use text|json: %v\n", err)
    os.Exit(2)
}

Prevention

When it happens

Trigger: Running the sensor with --log-format set to anything other than 'text' or 'json' (e.g. 'console', 'pretty', 'structured', empty string from an unset env var).

Common situations: Copy-pasting logrus/zap formatter names that the sensor does not support; Helm/kustomize template variable resolving to the wrong formatter name; upgrading the sensor and the old default format name was removed.

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/4f06ac1b677682d2. Report an issue: GitHub.