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
- Set --log-format to exactly 'json' or 'text'.
- If using templated config, ensure the variable resolves to one of the supported values and is non-empty.
- 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
- Only pass 'text' or 'json' (lowercase) as --log-format.
- Normalize template variables with strings.ToLower before injecting.
- Fail fast in CI by starting the sensor with its production flags in a smoke test.
- Document supported formats where the flag is defined.
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
- failed to set log-level: %v
- unknown log-format %q
- failed to set log output destination to %q, touch failed wit
- unknown log-level %q
- No global params
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/4f06ac1b677682d2.
Report an issue: GitHub.