{"record":{"id":"26fc601691bea084","repo":"uber-go/zap","slug":"invalid-increase-level-as-level-q-is-allowed-by","errorCode":null,"errorMessage":"invalid increase level, as level %q is allowed by increased level, but not by existing core","messagePattern":"invalid increase level, as level %q is allowed by increased level, but not by existing core","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"zapcore/increase_level.go","lineNumber":42,"sourceCode":"\ntype levelFilterCore struct {\n\tcore  Core\n\tlevel LevelEnabler\n}\n\nvar (\n\t_ Core           = (*levelFilterCore)(nil)\n\t_ leveledEnabler = (*levelFilterCore)(nil)\n)\n\n// NewIncreaseLevelCore creates a core that can be used to increase the level of\n// an existing Core. It cannot be used to decrease the logging level, as it acts\n// as a filter before calling the underlying core. If level decreases the log level,\n// an error is returned.\nfunc NewIncreaseLevelCore(core Core, level LevelEnabler) (Core, error) {\n\tfor l := _maxLevel; l >= _minLevel; l-- {\n\t\tif !core.Enabled(l) && level.Enabled(l) {\n\t\t\treturn nil, fmt.Errorf(\"invalid increase level, as level %q is allowed by increased level, but not by existing core\", l)\n\t\t}\n\t}\n\n\treturn &levelFilterCore{core, level}, nil\n}\n\nfunc (c *levelFilterCore) Enabled(lvl Level) bool {\n\treturn c.level.Enabled(lvl)\n}\n\nfunc (c *levelFilterCore) Level() Level {\n\treturn LevelOf(c.level)\n}\n\nfunc (c *levelFilterCore) With(fields []Field) Core {\n\treturn &levelFilterCore{c.core.With(fields), c.level}\n}\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/uber-go/zap/blob/bbd4ecbd8760678fdbac94c93d9aca8069c83b2f/zapcore/increase_level.go#L24-L60","documentation":"NewIncreaseLevelCore wraps a Core with a level filter that may only RAISE the effective logging level. It scans all levels from max to min; if the new LevelEnabler enables a level that the existing core does not (i.e. a decrease), construction fails with this error.","triggerScenarios":"Calling zapcore.NewIncreaseLevelCore(core, level) where level.Enabled(l) is true for some l that core.Enabled(l) is false — e.g. wrapping a core configured at ErrorLevel with an enabler for InfoLevel, or using an atomic level that was lowered.","commonSituations":"Dynamically changing log levels at runtime via zap.AtomicLevel and wrapping with NewIncreaseLevelCore while passing a lower verbosity than the base config; tests asserting level decreases are rejected; misordering WrapCore options.","solutions":["Ensure the passed LevelEnabler's level is >= the base core's level (e.g. increase from Info to Error, not the reverse).","If you need to lower verbosity, rebuild the base core/logger with the desired level instead of using NewIncreaseLevelCore.","Check that the atomic level backing the enabler wasn't mutated to a lower value before the call."],"exampleFix":"// before\nzapcore.NewIncreaseLevelCore(core, zap.NewAtomicLevelAt(zapcore.DebugLevel)) // decrease\n// after\nzapcore.NewIncreaseLevelCore(core, zap.NewAtomicLevelAt(zapcore.ErrorLevel)) // increase","handlingStrategy":"validation","validationCode":"newLvl := zap.NewAtomicLevelAt(zapcore.ErrorLevel)\nfor l := zapcore.FatalLevel; l >= zapcore.DebugLevel; l-- {\n    if newLvl.Enabled(l) && !baseCore.Enabled(l) {\n        return fmt.Errorf(\"cannot decrease to %s\", l)\n    }\n}\ncore, err := zapcore.NewIncreaseLevelCore(baseCore, newLvl)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only pass level enablers at or above the base core's level to NewIncreaseLevelCore.","For dynamic level changes in both directions, use the base logger's AtomicLevel instead.","Test runtime level changes for both increase and decrease paths."],"tags":["level","configuration","zapcore"],"backgroundTag":"log-level-decrease-not-allowed","analyzedSha":"bbd4ecbd8760678fdbac94c93d9aca8069c83b2f","analyzedAt":"2026-08-31T13:01:40.228Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}