{"record":{"id":"61a1057fdcac7b07","repo":"googleapis/mcp-toolbox","slug":"invalid-log-level","errorCode":null,"errorMessage":"invalid log level","messagePattern":"invalid log level","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/log/log.go","lineNumber":110,"sourceCode":"\tDebug = \"DEBUG\"\n\tInfo  = \"INFO\"\n\tWarn  = \"WARN\"\n\tError = \"ERROR\"\n)\n\n// Returns severity level based on string.\nfunc SeverityToLevel(s string) (slog.Level, error) {\n\tswitch strings.ToUpper(s) {\n\tcase Debug:\n\t\treturn slog.LevelDebug, nil\n\tcase Info:\n\t\treturn slog.LevelInfo, nil\n\tcase Warn:\n\t\treturn slog.LevelWarn, nil\n\tcase Error:\n\t\treturn slog.LevelError, nil\n\tdefault:\n\t\treturn slog.Level(-5), fmt.Errorf(\"invalid log level\")\n\t}\n}\n\n// Returns severity string based on level.\nfunc levelToSeverity(s string) (string, error) {\n\tswitch s {\n\tcase slog.LevelDebug.String():\n\t\treturn Debug, nil\n\tcase slog.LevelInfo.String():\n\t\treturn Info, nil\n\tcase slog.LevelWarn.String():\n\t\treturn Warn, nil\n\tcase slog.LevelError.String():\n\t\treturn Error, nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"invalid slog level\")\n\t}\n}","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/log/log.go#L92-L128","documentation":"SeverityToLevel maps the library's Severity constants (Debug, Info, Warn, Error) to slog.Level values. It returns this error when the input severity string matches none of the known cases, so the logger cannot translate it into a slog level. This guards against typo'd or future-unknown severity values passed to NewStdLogger/NewStructuredLogger.","triggerScenarios":"Calling SeverityToLevel (directly or via NewStdLogger/NewStructuredLogger/server startup logging config) with a severity string other than \"DEBUG\",\"INFO\",\"WARN\",\"ERROR\" — e.g. \"warning\", \"verbose\", an empty string, or a lowercased value.","commonSituations":"A CLI flag --log-level=warning is used instead of WARN; an env var like LOG_SEVERITY is unset or contains trailing whitespace; a user invents a level like TRACE that the library does not support.","solutions":["Use one of the supported severity values exactly: Debug, Info, Warn, Error (matching the Severity constants' String() values).","Normalize/trim the input (strings.TrimSpace, strings.ToUpper) before passing it to SeverityToLevel or the logger constructors.","Inspect the error returned from NewStdLogger/NewStructuredLogger at startup and fail fast with a message listing valid levels."],"exampleFix":"// before\nlogger, err := log.NewStructuredLogger(\"warning\", os.Stderr)\n// after\nlogger, err := log.NewStructuredLogger(\"WARN\", os.Stderr)","handlingStrategy":"validation","validationCode":"func validSeverity(s string) bool {\n\tswitch strings.ToUpper(strings.TrimSpace(s)) {\n\tcase \"DEBUG\", \"INFO\", \"WARN\", \"ERROR\":\n\t\treturn true\n\t}\n\treturn false\n}\nif !validSeverity(flagLevel) {\n\treturn fmt.Errorf(\"--log-level must be one of DEBUG|INFO|WARN|ERROR, got %q\", flagLevel)\n}","typeGuard":"func isSeverity(s string) bool {\n\tswitch log.Severity(s) {\n\tcase log.Debug, log.Info, log.Warn, log.Error:\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":"logger, err := log.NewStructuredLogger(level, os.Stderr)\nif err != nil {\n\tif strings.Contains(err.Error(), \"invalid log level\") {\n\t\tlog.Fatalf(\"invalid --log-level %q; use DEBUG|INFO|WARN|ERROR\", level)\n\t}\n\tlog.Fatal(err)\n}","preventionTips":["Define allowed log levels as an enum/flag choice list in your CLI, not a free-form string.","Normalize input with strings.ToUpper(strings.TrimSpace(...)) before mapping.","Fail fast at startup with a message listing valid values."],"tags":["logging","configuration","go"],"backgroundTag":"invalid-log-level","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}