/
log.go
82 lines (64 loc) · 1.98 KB
/
log.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
package utils
import (
"io"
"os"
"gopkg.in/urfave/cli.v1"
colorable "github.com/mattn/go-colorable"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log/term"
tmlog "github.com/tendermint/tendermint/libs/log"
)
var glogger *log.GlogHandler
func init() {
usecolor := term.IsTty(os.Stderr.Fd()) && os.Getenv("TERM") != "dumb"
output := io.Writer(os.Stderr)
if usecolor {
output = colorable.NewColorableStderr()
}
glogger = log.NewGlogHandler(log.StreamHandler(output, log.TerminalFormat(usecolor)))
}
// Setup sets up the logging infrastructure
// #unstable
func Setup(ctx *cli.Context) error {
glogger.Verbosity(log.Lvl(ctx.GlobalInt(VerbosityFlag.Name)))
log.Root().SetHandler(glogger)
return nil
}
// ---------------------------
// EthermintLogger - wraps the logger in tmlibs
// Interface assertions
var _ tmlog.Logger = (*ethermintLogger)(nil)
type ethermintLogger struct {
keyvals []interface{}
}
// EthermintLogger returns a new instance of an ethermint logger. With() should
// be called upon the returned instance to set default keys
// #unstable
func EthermintLogger() tmlog.Logger {
logger := ethermintLogger{keyvals: make([]interface{}, 0)}
return logger
}
// Debug proxies everything to the go-ethereum logging facilities
// #unstable
func (l ethermintLogger) Debug(msg string, ctx ...interface{}) {
ctx = append(l.keyvals, ctx...)
log.Debug(msg, ctx...)
}
// Info proxies everything to the go-ethereum logging facilities
// #unstable
func (l ethermintLogger) Info(msg string, ctx ...interface{}) {
ctx = append(l.keyvals, ctx...)
log.Info(msg, ctx...)
}
// Error proxies everything to the go-ethereum logging facilities
// #unstable
func (l ethermintLogger) Error(msg string, ctx ...interface{}) {
ctx = append(l.keyvals, ctx...)
log.Error(msg, ctx...)
}
// With proxies everything to the go-ethereum logging facilities
// #unstable
func (l ethermintLogger) With(ctx ...interface{}) tmlog.Logger {
l.keyvals = append(l.keyvals, ctx...)
return l
}