{"record":{"id":"2a0a138bfd903c28","repo":"slimtoolkit/slim","slug":"unknown-log-format-q","errorCode":null,"errorMessage":"unknown log-format %q","messagePattern":"unknown log-format %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/sensor/logger.go","lineNumber":52,"sourceCode":"\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}\n\nfunc setLogFormat(format string) error {\n\tswitch format {\n\tcase \"text\":\n\t\tlog.SetFormatter(&log.TextFormatter{DisableColors: true})\n\tcase \"json\":\n\t\tlog.SetFormatter(&log.JSONFormatter{})\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown log-format %q\", format)\n\t}\n\n\treturn nil\n}\n\nfunc setLogLevel(enableDebug bool, levelName string) error {\n\tif enableDebug {\n\t\tlog.SetLevel(log.DebugLevel)\n\t\treturn nil\n\t}\n\n\tvar logLevel log.Level\n\n\tswitch levelName {\n\tcase \"trace\":\n\t\tlogLevel = log.TraceLevel\n\tcase \"debug\":\n\t\tlogLevel = log.DebugLevel","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/sensor/logger.go#L34-L70","documentation":"setLogFormat maps the configured format string to a logrus formatter: 'text' uses a colorless TextFormatter, 'json' uses JSONFormatter. Any other value falls into the default branch and returns this error, which configureLogger surfaces as 'failed to set log format'.","triggerScenarios":"Passing a --log-format value other than 'text' or 'json' to the sensor, including empty strings from unset environment variables or templating mistakes.","commonSituations":"Users try formatter names from other logging libraries ('console', 'cli', 'logfmt'); CI injects an unsupported default; a typo such as 'jsn' or 'JSON' (case-sensitive switch).","solutions":["Use exactly 'text' or 'json' (lowercase) for --log-format.","If the value comes from an env var or template, validate/normalize it (strings.TrimSpace, lowercase) before passing it.","Omit the flag entirely to keep the default formatter."],"exampleFix":"// before\nif format == \"\" { format = \"JSON\" } // wrong casing/empty\n// after\nformat = strings.ToLower(strings.TrimSpace(format))\nif format != \"text\" && format != \"json\" { format = \"text\" }","handlingStrategy":"validation","validationCode":"func normalizeFormat(f string) string {\n    f = strings.ToLower(strings.TrimSpace(f))\n    if f != \"text\" && f != \"json\" { return \"text\" }\n    return f\n}","typeGuard":"func isUnknownFormatError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"unknown log-format\")\n}","tryCatchPattern":"if err := Run(ctx); err != nil && strings.Contains(err.Error(), \"unknown log-format\") {\n    fmt.Fprintf(os.Stderr, \"unsupported format, must be text or json: %v\\n\", err)\n    os.Exit(2)\n}","preventionTips":["Use a small allowlist (text|json) at the config boundary and reject anything else early.","Lowercase and trim any format value sourced from env vars or templates.","Add a startup smoke test that exercises the configured log format.","Prefer omitting the flag and relying on the default formatter."],"tags":["logging","configuration","invalid-input","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}