{"record":{"id":"dff253455c37d9cc","repo":"micro/go-micro","slug":"unknown-level-string-s-defaulting-to-infoleve","errorCode":null,"errorMessage":"unknown Level String: '%s', defaulting to InfoLevel","messagePattern":"unknown Level String: '(.+?)', defaulting to InfoLevel","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"logger/level.go","lineNumber":92,"sourceCode":"\n// GetLevel converts a level string into a logger Level value.\n// returns an error if the input string does not match known values.\nfunc GetLevel(levelStr string) (Level, error) {\n\tswitch levelStr {\n\tcase TraceLevel.String():\n\t\treturn TraceLevel, nil\n\tcase DebugLevel.String():\n\t\treturn DebugLevel, nil\n\tcase InfoLevel.String():\n\t\treturn InfoLevel, nil\n\tcase WarnLevel.String():\n\t\treturn WarnLevel, nil\n\tcase ErrorLevel.String():\n\t\treturn ErrorLevel, nil\n\tcase FatalLevel.String():\n\t\treturn FatalLevel, nil\n\t}\n\treturn InfoLevel, fmt.Errorf(\"unknown Level String: '%s', defaulting to InfoLevel\", levelStr)\n}\n\nfunc Info(args ...interface{}) {\n\tDefaultLogger.Log(InfoLevel, args...)\n}\n\nfunc Infof(template string, args ...interface{}) {\n\tDefaultLogger.Logf(InfoLevel, template, args...)\n}\n\nfunc Trace(args ...interface{}) {\n\tDefaultLogger.Log(TraceLevel, args...)\n}\n\nfunc Tracef(template string, args ...interface{}) {\n\tDefaultLogger.Logf(TraceLevel, template, args...)\n}\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/logger/level.go#L74-L110","documentation":"GetLevel converts a level string (from config/env) into a Level constant by comparing against each level's String(). If the string matches no known level it logs at InfoLevel by default and returns this error describing the unrecognized value.","triggerScenarios":"Calling GetLevel (typically from an init() that reads a config/env variable like LOGGER_LEVEL) with a value that is not trace/debug/info/warn/warning/error/fatal — including typos, wrong casing beyond what String comparison tolerates, or trailing whitespace.","commonSituations":"Misconfigured environment variable (e.g. LOG_LEVEL=VERBOSE or 'info ' with a trailing space), deployment configs carrying level names from another logging library, or an unset/blank variable reaching the parser.","solutions":["Fix the level string in the config/env to an exact supported value: debug, info, warn, error, or fatal.","Trim whitespace and normalize case before calling GetLevel.","Treat the returned error in the caller: either abort startup or accept the InfoLevel default explicitly.","If you need custom levels, extend the switch/parse logic rather than passing unsupported strings."],"exampleFix":"// before\nlogger.SetLevel(logger.GetLevel(os.Getenv(\"LOG_LEVEL\")))\n\n// after\nlvl, err := logger.GetLevel(strings.TrimSpace(strings.ToLower(os.Getenv(\"LOG_LEVEL\"))))\nif err != nil {\n    log.Printf(\"config warning: %v\", err)\n}\nlogger.SetLevel(lvl)","handlingStrategy":"validation","validationCode":"var validLevels = map[string]bool{\"debug\": true, \"info\": true, \"warn\": true, \"warning\": true, \"error\": true, \"fatal\": true}\nfunc levelIsValid(s string) bool {\n    return validLevels[strings.ToLower(strings.TrimSpace(s))]\n}\nraw := strings.TrimSpace(os.Getenv(\"LOG_LEVEL\"))\nif raw != \"\" && !levelIsValid(raw) {\n    log.Printf(\"warning: unknown LOG_LEVEL %q, using info\", raw)\n}","typeGuard":null,"tryCatchPattern":"lvl, err := logger.GetLevel(cfg.Level)\nif err != nil {\n    log.Printf(\"log config: %v\", err) // library already defaults to InfoLevel\n    lvl = logger.InfoLevel\n}\nlogger.SetLevel(lvl)","preventionTips":["Validate level strings against the supported set at config-load time, before logger init.","Normalize with strings.ToLower and strings.TrimSpace on env/config input.","Document the accepted level names where the deployment config lives.","Fail fast at startup for unknown levels if silent InfoLevel fallback is undesirable."],"tags":["logging","configuration","log-level"],"backgroundTag":"invalid-log-level","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}