forked from ipfs/go-log
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.go
More file actions
33 lines (27 loc) · 726 Bytes
/
core.go
File metadata and controls
33 lines (27 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package log
import (
"go.uber.org/zap/zapcore"
)
// Created new interface without LevelEnabler because interface overlapping didn't work yet on 1.13
type AlmostCore interface {
With([]zapcore.Field) zapcore.Core
Check(zapcore.Entry, *zapcore.CheckedEntry) *zapcore.CheckedEntry
Write(zapcore.Entry, []zapcore.Field) error
Sync() error
}
func WrapCore(core zapcore.Core, level zapcore.LevelEnabler) zapcore.Core {
return &coreWrapper{
LevelEnabler: level,
AlmostCore: core,
}
}
type coreWrapper struct {
zapcore.LevelEnabler
AlmostCore
}
func (c *coreWrapper) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry {
if c.Enabled(ent.Level) {
return ce.AddCore(ent, c)
}
return ce
}