slimtoolkit/slim · error
failed to set log-level: %v
Error message
failed to set log-level: %v
What it means
configureLogger (called from Run) first applies the log level via setLogLevel, which combines the enableDebug flag with the --log-level name. If setLogLevel rejects the input (unknown level name or invalid combination), configureLogger wraps and returns this error, so the sensor fails fast at startup rather than logging silently.
Source
Thrown at pkg/app/sensor/logger.go:21
package sensor
import (
"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)View on GitHub (pinned to 81940d17fa)
Solutions
- Set --log-level to a supported level name (e.g. debug, info, warn, error) as the wrapped %v error indicates.
- Drop the custom level and rely on the boolean enableDebug flag for debug output.
- Check the sensor's logger.go setLogLevel implementation for the exact accepted values.
Example fix
// before args: ["--log-level", "verbose"] // after args: ["--log-level", "debug"]
Defensive patterns
Strategy: validation
Validate before calling
var validLevels = map[string]bool{"debug": true, "info": true, "warn": true, "warning": true, "error": true, "fatal": true, "trace": true}
func validLogLevel(name string) bool { return validLevels[strings.ToLower(strings.TrimSpace(name))] } Type guard
func isLogLevelError(err error) bool {
return err != nil && strings.Contains(err.Error(), "failed to set log-level")
} Try / catch
if err := Run(ctx); err != nil && strings.Contains(err.Error(), "failed to set log-level") {
fmt.Fprintf(os.Stderr, "bad --log-level, use debug|info|warn|error: %v\n", err)
os.Exit(2)
} Prevention
- Whitelist/normalize level values in your Helm/kustomize templates.
- Default to 'info' when the env var or flag is empty.
- Test sensor startup with the exact configured flags in CI.
- Keep an enumeration of supported levels next to deployment config.
When it happens
Trigger: Running the sensor with a --log-level value that setLogLevel cannot parse (e.g. 'verbose', 'warn2', typo like 'infro'), or a level string that conflicts with enableDebug handling.
Common situations: Deployment YAML passes a custom log level name the sensor does not support; configuration templating injects an empty or malformed level; users assume arbitrary zap/logrus level names are accepted.
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 format: %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/514328ea76f8cfab.
Report an issue: GitHub.