{"record":{"id":"58803efed54eabc7","repo":"uber-go/zap","slug":"unrecognized-level-q","errorCode":null,"errorMessage":"unrecognized level: %q","messagePattern":"unrecognized level: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"global.go","lineNumber":158,"sourceCode":"\nfunc levelToFunc(logger *Logger, lvl zapcore.Level) (func(string, ...Field), error) {\n\tswitch lvl {\n\tcase DebugLevel:\n\t\treturn logger.Debug, nil\n\tcase InfoLevel:\n\t\treturn logger.Info, nil\n\tcase WarnLevel:\n\t\treturn logger.Warn, nil\n\tcase ErrorLevel:\n\t\treturn logger.Error, nil\n\tcase DPanicLevel:\n\t\treturn logger.DPanic, nil\n\tcase PanicLevel:\n\t\treturn logger.Panic, nil\n\tcase FatalLevel:\n\t\treturn logger.Fatal, nil\n\t}\n\treturn nil, fmt.Errorf(\"unrecognized level: %q\", lvl)\n}\n\ntype loggerWriter struct {\n\tlogFunc func(msg string, fields ...Field)\n}\n\nfunc (l *loggerWriter) Write(p []byte) (int, error) {\n\tp = bytes.TrimSpace(p)\n\tl.logFunc(string(p))\n\treturn len(p), nil\n}\n","sourceCodeStart":140,"sourceCodeEnd":170,"githubUrl":"https://github.com/uber-go/zap/blob/bbd4ecbd8760678fdbac94c93d9aca8069c83b2f/global.go#L140-L170","documentation":"levelToFunc in global.go maps a zapcore.Level string (via levelToFunc's caller's parsed level) to the corresponding logger method for redirecting std log output. When the supplied level string does not match any known zap level (Debug, Info, Warn, Error, DPanic, Panic, Fatal), it returns this error. It means the level value passed to NewStdLogAt or redirectStdLogAt was not a recognized zap level.","triggerScenarios":"Calling zap.NewStdLogAt(l, level) or zap.RedirectStdLogAt(l, level) with a level string that is not one of debug/info/warn/error/dpanic/panic/fatal (case variations or typos like 'trace' or 'verbose' are rejected).","commonSituations":"Level names read from environment variables or config files that use non-zap naming conventions (e.g. 'trace', 'verbose', 'notice', or uppercase 'DEBUG' if parsed case-sensitively by the caller), or typos in programmatic level constants.","solutions":["Use one of the recognized level strings: debug, info, warn, error, dpanic, panic, fatal.","Normalize user/config input with zapcore.ParseLevel or strings.ToLower before passing to NewStdLogAt/RedirectStdLogAt.","Handle the returned error by falling back to a default level (e.g. InfoLevel) instead of failing startup."],"exampleFix":"// before\nlogger, err := zap.NewStdLogAt(zapLog, \"verbose\")\n// after\nlvl, perr := zapcore.ParseLevel(\"verbose\") // still fails; validate input first\nif perr != nil {\n    lvl = zapcore.InfoLevel\n}\nlogger, err := zap.NewStdLogAt(zapLog, lvl.String())","handlingStrategy":"validation","validationCode":"func validZapLevel(s string) bool {\n    switch strings.ToLower(strings.TrimSpace(s)) {\n    case \"debug\", \"info\", \"warn\", \"error\", \"dpanic\", \"panic\", \"fatal\":\n        return true\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"lvl, err := zapcore.ParseLevel(cfg.Level)\nif err != nil {\n    lvl = zapcore.InfoLevel // fallback\n}\nstdLog, err := zap.NewStdLogAt(zapLog, lvl)","preventionTips":["Always build levels via zapcore.ParseLevel rather than raw strings","Normalize case and trim whitespace from config/env level values","Add a startup-time config validation step that rejects unknown levels early"],"tags":["zap","logging","configuration","invalid-level"],"backgroundTag":"invalid-log-level","analyzedSha":"bbd4ecbd8760678fdbac94c93d9aca8069c83b2f","analyzedAt":"2026-08-31T13:01:40.228Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}