NewIncreaseLevelCore creates a core that can be used to increase the level of an existing Core. It cannot be used to decrease the logging level, as it acts as a filter before calling the underlying core. If level decreases the log level, an error is returned.
(core Core, level LevelEnabler)
| 37 | // as a filter before calling the underlying core. If level decreases the log level, |
| 38 | // an error is returned. |
| 39 | func NewIncreaseLevelCore(core Core, level LevelEnabler) (Core, error) { |
| 40 | for l := _maxLevel; l >= _minLevel; l-- { |
| 41 | if !core.Enabled(l) && level.Enabled(l) { |
| 42 | return nil, fmt.Errorf("invalid increase level, as level %q is allowed by increased level, but not by existing core", l) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | return &levelFilterCore{core, level}, nil |
| 47 | } |
| 48 | |
| 49 | func (c *levelFilterCore) Enabled(lvl Level) bool { |
| 50 | return c.level.Enabled(lvl) |