forked from eoscanada/eos-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
49 lines (40 loc) · 952 Bytes
/
logger.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
package eos
import (
"fmt"
"go.uber.org/zap"
)
var encoderLog = zap.NewNop()
var decoderLog = zap.NewNop()
var abiEncoderLog = zap.NewNop()
var abiDecoderLog = zap.NewNop()
func EnableEncoderLogging() {
encoderLog = newLogger(false)
}
func EnableDecoderLogging() {
decoderLog = newLogger(false)
}
func EnableABIEncoderLogging() {
abiEncoderLog = newLogger(false)
}
func EnableABIDecoderLogging() {
abiDecoderLog = newLogger(false)
}
type logStringerFunc func() string
func (f logStringerFunc) String() string { return f() }
func typeField(field string, v interface{}) zap.Field {
return zap.Stringer(field, logStringerFunc(func() string {
return fmt.Sprintf("%T", v)
}))
}
func newLogger(production bool) (l *zap.Logger) {
if production {
l, _ = zap.NewProduction()
} else {
l, _ = zap.NewDevelopment()
}
return
}
// NewLogger a wrap to newLogger
func NewLogger(production bool) *zap.Logger {
return newLogger(production)
}