{"record":{"id":"4f06ac1b677682d2","repo":"slimtoolkit/slim","slug":"failed-to-set-log-format-v","errorCode":null,"errorMessage":"failed to set log format: %v","messagePattern":"failed to set log format: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/logger.go","lineNumber":25,"sourceCode":"\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)\n\t}\n\n\treturn nil\n}","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/logger.go#L7-L43","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nargs: [\"--log-format\", \"console\"]\n// after\nargs: [\"--log-format\", \"json\"]","handlingStrategy":"validation","validationCode":"func validLogFormat(f string) bool {\n    f = strings.ToLower(strings.TrimSpace(f))\n    return f == \"text\" || f == \"json\"\n}","typeGuard":"func isLogFormatError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"failed to set log format\")\n}","tryCatchPattern":"if err := Run(ctx); err != nil && strings.Contains(err.Error(), \"failed to set log format\") {\n    fmt.Fprintf(os.Stderr, \"bad --log-format, use text|json: %v\\n\", err)\n    os.Exit(2)\n}","preventionTips":["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."],"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"}