-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
sugared.go
36 lines (30 loc) · 1.09 KB
/
sugared.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
package logger
// SugaredLogger extends the base Logger interface with syntactic sugar, similar to zap.SugaredLogger.
type SugaredLogger interface {
Logger
AssumptionViolation(args ...interface{})
AssumptionViolationf(format string, vals ...interface{})
AssumptionViolationw(msg string, keyvals ...interface{})
}
func Sugared(l Logger) SugaredLogger {
return &sugared{
Logger: l,
h: l.Helper(1),
}
}
type sugared struct {
Logger
h Logger // helper with stack trace skip level
}
// AssumptionViolation wraps Error logs with assumption violation tag.
func (s *sugared) AssumptionViolation(args ...interface{}) {
s.h.Error(append([]interface{}{"AssumptionViolation:"}, args...))
}
// AssumptionViolationf wraps Errorf logs with assumption violation tag.
func (s *sugared) AssumptionViolationf(format string, vals ...interface{}) {
s.h.Errorf("AssumptionViolation: "+format, vals...)
}
// AssumptionViolationw wraps Errorw logs with assumption violation tag.
func (s *sugared) AssumptionViolationw(msg string, keyvals ...interface{}) {
s.h.Errorw("AssumptionViolation: "+msg, keyvals...)
}