-
Notifications
You must be signed in to change notification settings - Fork 3
/
sentry_core_wrapper.go
58 lines (48 loc) · 1.46 KB
/
sentry_core_wrapper.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package logger
import (
"github.com/getsentry/sentry-go"
"go.uber.org/multierr"
"go.uber.org/zap/zapcore"
)
// sentryCoreWrapper is something like multiCore but only for two cores when second core is a Sentry core.
type sentryCoreWrapper [2]zapcore.Core
// NewSentryCoreWrapper creates a Core that duplicates log entries into
// provided local Core and implicitly created Sentry core.
func NewSentryCoreWrapper(localCore zapcore.Core, hub *sentry.Hub, options ...SentryCoreOption) zapcore.Core {
return sentryCoreWrapper{
localCore,
NewSentryCore(hub, options...),
}
}
func (w sentryCoreWrapper) LocalCore() zapcore.Core {
return w[0]
}
func (w sentryCoreWrapper) SentryCore() *SentryCore {
return w[1].(*SentryCore) //nolint: forcetypeassert
}
func (w sentryCoreWrapper) Enabled(lvl zapcore.Level) bool {
return w[0].Enabled(lvl) || w[1].Enabled(lvl)
}
func (w sentryCoreWrapper) With(fields []zapcore.Field) zapcore.Core {
return sentryCoreWrapper{
w.LocalCore().With(fields),
w.SentryCore().With(fields),
}
}
func (w sentryCoreWrapper) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry {
return w[0].Check(ent, w[1].Check(ent, ce))
}
func (w sentryCoreWrapper) Write(ent zapcore.Entry, fields []zapcore.Field) error {
//nolint:wrapcheck
return multierr.Append(
w[0].Write(ent, fields),
w[1].Write(ent, fields),
)
}
func (w sentryCoreWrapper) Sync() error {
//nolint:wrapcheck
return multierr.Append(
w[0].Sync(),
w[1].Sync(),
)
}