{"record":{"id":"514328ea76f8cfab","repo":"slimtoolkit/slim","slug":"failed-to-set-log-level-v","errorCode":null,"errorMessage":"failed to set log-level: %v","messagePattern":"failed to set log-level: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/logger.go","lineNumber":21,"sourceCode":"\npackage sensor\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\tlog \"github.com/sirupsen/logrus\"\n\t\"github.com/slimtoolkit/slim/pkg/util/fsutil\"\n)\n\nfunc configureLogger(\n\tenableDebug bool,\n\tlevelName string,\n\tformat string,\n\tlogFile string,\n) error {\n\tif err := setLogLevel(enableDebug, levelName); err != nil {\n\t\treturn fmt.Errorf(\"failed to set log-level: %v\", err)\n\t}\n\n\tif err := setLogFormat(format); err != nil {\n\t\treturn fmt.Errorf(\"failed to set log format: %v\", err)\n\t}\n\n\tif len(logFile) > 0 {\n\t\t// This touch is not ideal - need to understand how to merge this logic with artifacts.PrepareEnv().\n\t\tif err := fsutil.Touch(logFile); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set log output destination to %q, touch failed with: %v\", logFile, err)\n\t\t}\n\n\t\tf, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set log output destination to %q: %w\", logFile, err)\n\t\t}\n\n\t\tlog.SetOutput(f)","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/logger.go#L3-L39","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nargs: [\"--log-level\", \"verbose\"]\n// after\nargs: [\"--log-level\", \"debug\"]","handlingStrategy":"validation","validationCode":"var validLevels = map[string]bool{\"debug\": true, \"info\": true, \"warn\": true, \"warning\": true, \"error\": true, \"fatal\": true, \"trace\": true}\nfunc validLogLevel(name string) bool { return validLevels[strings.ToLower(strings.TrimSpace(name))] }","typeGuard":"func isLogLevelError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"failed to set log-level\")\n}","tryCatchPattern":"if err := Run(ctx); err != nil && strings.Contains(err.Error(), \"failed to set log-level\") {\n    fmt.Fprintf(os.Stderr, \"bad --log-level, use debug|info|warn|error: %v\\n\", err)\n    os.Exit(2)\n}","preventionTips":["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."],"tags":["logging","configuration","invalid-input","startup"],"backgroundTag":"invalid-config-value","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}