forked from celo-org/celo-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.go
81 lines (67 loc) · 2.32 KB
/
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
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
// Copyright 2017 The celo Authors
// This file is part of the celo library.
//
// The celo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The celo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the celo library. If not, see <http://www.gnu.org/licenses/>.
package istanbul
import (
"math/big"
"github.com/keep-network/celo-blockchain/common"
"github.com/keep-network/celo-blockchain/log"
)
type istLogger struct {
logger log.Logger
round func() *big.Int
}
// NewIstLogger creates an Istanbul Logger with custom logic for exposing logs
func NewIstLogger(fn func() *big.Int, ctx ...interface{}) log.Logger {
return &istLogger{logger: log.New(ctx...), round: fn}
}
func (l *istLogger) New(ctx ...interface{}) log.Logger {
childLogger := l.logger.New(ctx...)
return &istLogger{logger: childLogger, round: l.round}
}
func (l *istLogger) Trace(msg string, ctx ...interface{}) {
// If the current round > 1, then upgrade this message to Info
if l.round != nil && l.round() != nil && l.round().Cmp(common.Big1) > 0 {
l.Info(msg, ctx...)
} else {
l.logger.Trace(msg, ctx...)
}
}
func (l *istLogger) Debug(msg string, ctx ...interface{}) {
// If the current round > 1, then upgrade this message to Info
if l.round != nil && l.round() != nil && l.round().Cmp(common.Big1) > 0 {
l.Info(msg, ctx...)
} else {
l.logger.Debug(msg, ctx...)
}
}
func (l *istLogger) Info(msg string, ctx ...interface{}) {
l.logger.Info(msg, ctx...)
}
func (l *istLogger) Warn(msg string, ctx ...interface{}) {
l.logger.Warn(msg, ctx...)
}
func (l *istLogger) Error(msg string, ctx ...interface{}) {
l.logger.Error(msg, ctx...)
}
func (l *istLogger) Crit(msg string, ctx ...interface{}) {
l.logger.Crit(msg, ctx...)
}
func (l *istLogger) GetHandler() log.Handler {
return l.logger.GetHandler()
}
func (l *istLogger) SetHandler(h log.Handler) {
l.logger.SetHandler(h)
}