forked from eoscanada/eos-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.go
44 lines (34 loc) · 847 Bytes
/
logging.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
package eos
import (
"fmt"
"github.com/dfuse-io/logging"
"go.uber.org/zap"
)
var traceEnabled = logging.IsTraceEnabled("eos-go", "github.com/eoscanada/eos-go")
var zlog = zap.NewNop()
func init() {
logging.Register("github.com/eoscanada/eos-go", &zlog)
}
func EnableDebugLogging(l *zap.Logger) {
traceEnabled = true
zlog = l
}
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)
}