{"record":{"id":"a4c17417c721a874","repo":"uber-go/zap","slug":"underlying-error-from-the-wrapped-logger-error","errorCode":null,"errorMessage":"underlying error from the wrapped (*Logger, error) call","messagePattern":"underlying error from the wrapped \\(\\*Logger, error\\) call","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"logger.go","lineNumber":119,"sourceCode":"\treturn NewProductionConfig().Build(options...)\n}\n\n// NewDevelopment builds a development Logger that writes DebugLevel and above\n// logs to standard error in a human-friendly format.\n//\n// It's a shortcut for NewDevelopmentConfig().Build(...Option).\nfunc NewDevelopment(options ...Option) (*Logger, error) {\n\treturn NewDevelopmentConfig().Build(options...)\n}\n\n// Must is a helper that wraps a call to a function returning (*Logger, error)\n// and panics if the error is non-nil. It is intended for use in variable\n// initialization such as:\n//\n//\tvar logger = zap.Must(zap.NewProduction())\nfunc Must(logger *Logger, err error) *Logger {\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\treturn logger\n}\n\n// NewExample builds a Logger that's designed for use in zap's testable\n// examples. It writes DebugLevel and above logs to standard out as JSON, but\n// omits the timestamp and calling function to keep example output\n// short and deterministic.\nfunc NewExample(options ...Option) *Logger {\n\tencoderCfg := zapcore.EncoderConfig{\n\t\tMessageKey:     \"msg\",\n\t\tLevelKey:       \"level\",\n\t\tNameKey:        \"logger\",\n\t\tEncodeLevel:    zapcore.LowercaseLevelEncoder,\n\t\tEncodeTime:     zapcore.ISO8601TimeEncoder,\n\t\tEncodeDuration: zapcore.StringDurationEncoder,\n\t}","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/uber-go/zap/blob/bbd4ecbd8760678fdbac94c93d9aca8069c83b2f/logger.go#L101-L137","documentation":"zap.Must panics with the error returned by a (*Logger, error) constructor (e.g. zap.NewProduction or a Config.Build) if that error is non-nil. The panic value is the underlying error itself, so the runtime message shows the wrapped cause of logger construction failure.","triggerScenarios":"Package-level var logger = zap.Must(zap.NewProduction()) (or zap.Must(cfg.Build())) when construction fails: invalid config paths, unreadable output files, invalid encoding names, unparseable level strings in the config.","commonSituations":"Program startup crashing at var-initialization time because the log file path is unwritable in a container, or a config with an invalid OutputPaths/Level value; commonly seen when deploying to restricted environments where /var/log isn't writable.","solutions":["Inspect the panic message for the wrapped cause (e.g. \"open sink ...: permission denied\") and fix the config/path.","If construction may legitimately fail, use the (logger, err) form instead of Must and handle the error, falling back to zap.NewNop().","Ensure output directories exist and are writable before the logger is constructed.","Validate the Config (level names, encodings, paths) before calling Build."],"exampleFix":"// before\nvar logger = zap.Must(zap.NewProduction()) // panics on failure\n// after\nlogger, err := zap.NewProduction()\nif err != nil {\n    logger = zap.NewNop()\n}","handlingStrategy":"try-catch","validationCode":"// Validate config before Must-style construction:\nfor _, p := range cfg.OutputPaths {\n    if p != \"stderr\" && p != \"stdout\" {\n        if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil { return err }\n    }\n}\nif _, err := zapcore.ParseLevel(cfg.Level.Level().String()); err != nil { return err }","typeGuard":null,"tryCatchPattern":"func initLogger() *zap.Logger {\n    l, err := zap.NewProduction()\n    if err != nil {\n        fmt.Fprintf(os.Stderr, \"logger init failed: %v\\n\", err)\n        return zap.NewNop()\n    }\n    return l\n}\nvar logger = initLogger()","preventionTips":["Avoid zap.Must in package-level vars for deploy targets with uncertain filesystem permissions.","Verify output paths are writable as the runtime user (especially in containers).","Validate the entire Config (levels, encodings, paths) before Build().","Keep a fallback (Nop or stderr) logger so the process can still start."],"tags":["panic","initialization","logger-config"],"backgroundTag":"must-panic-on-logger-construction","analyzedSha":"bbd4ecbd8760678fdbac94c93d9aca8069c83b2f","analyzedAt":"2026-08-31T13:01:40.228Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}