forked from celer-network/eth-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logrus.go
92 lines (72 loc) · 2.67 KB
/
logrus.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package logger
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/begmaroman/eth-services/types"
)
var _ types.Logger = (*Logrus)(nil)
type Logrus struct {
logrus.FieldLogger
}
// NewLogrus creates a wrapped Logrus logger
func NewLogrus(logger logrus.FieldLogger) *Logrus {
return &Logrus{
FieldLogger: logger,
}
}
// Trace is a shim stand-in for when we have real trace-level logging support
func (l *Logrus) Trace(args ...interface{}) {
l.Debug(append([]interface{}{"TRACE: "}, args...))
}
// Tracef is a shim stand-in for when we have real trace-level logging support
func (l *Logrus) Tracef(format string, values ...interface{}) {
l.Debugf("TRACE: %s", fmt.Sprintf(format, values...))
}
// Tracew is a shim stand-in for when we have real trace-level logging support
func (l *Logrus) Tracew(msg string, keysAndValues ...interface{}) {
fields := logrus.Fields{}
for i := 0; i < len(keysAndValues); i += 2 {
fields[fmt.Sprintf("%v", keysAndValues[i])] = keysAndValues[i+1]
}
l.WithFields(fields).Debug("TRACE: " + msg)
}
// Debugw is a shim stand-in for when we have real debug-level logging support
func (l *Logrus) Debugw(msg string, keysAndValues ...interface{}) {
fields := logrus.Fields{}
for i := 0; i < len(keysAndValues); i += 2 {
fields[fmt.Sprintf("%v", keysAndValues[i])] = keysAndValues[i+1]
}
l.WithFields(fields).Debug("DEBUG: " + msg)
}
// Infow is a shim stand-in for when we have real info-level logging support
func (l *Logrus) Infow(msg string, keysAndValues ...interface{}) {
fields := logrus.Fields{}
for i := 0; i < len(keysAndValues); i += 2 {
fields[fmt.Sprintf("%v", keysAndValues[i])] = keysAndValues[i+1]
}
l.WithFields(fields).Info("INFO: " + msg)
}
// Warnw is a shim stand-in for when we have real warn-level logging support
func (l *Logrus) Warnw(msg string, keysAndValues ...interface{}) {
fields := logrus.Fields{}
for i := 0; i < len(keysAndValues); i += 2 {
fields[fmt.Sprintf("%v", keysAndValues[i])] = keysAndValues[i+1]
}
l.WithFields(fields).Warn("WARN: " + msg)
}
// Errorw is a shim stand-in for when we have real error-level logging support
func (l *Logrus) Errorw(msg string, keysAndValues ...interface{}) {
fields := logrus.Fields{}
for i := 0; i < len(keysAndValues); i += 2 {
fields[fmt.Sprintf("%v", keysAndValues[i])] = keysAndValues[i+1]
}
l.WithFields(fields).Error("ERROR: " + msg)
}
// Panicw is a shim stand-in for when we have real panic-level logging support
func (l *Logrus) Panicw(msg string, keysAndValues ...interface{}) {
fields := logrus.Fields{}
for i := 0; i < len(keysAndValues); i += 2 {
fields[fmt.Sprintf("%v", keysAndValues[i])] = keysAndValues[i+1]
}
l.WithFields(fields).Panic("PANIC: " + msg)
}