-
Notifications
You must be signed in to change notification settings - Fork 45
/
logging.go
51 lines (42 loc) · 1.22 KB
/
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
45
46
47
48
49
50
51
package superviser
import (
"regexp"
"strings"
logplugin "github.com/dfuse-io/node-manager/log_plugin"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var logLevelRegex = regexp.MustCompile("^(<[0-9]>)?(info|warn|error)")
func newToZapLogPlugin(debugDeepMind bool, logger *zap.Logger) *logplugin.ToZapLogPlugin {
return logplugin.NewToZapLogPlugin(debugDeepMind, logger, logplugin.ToZapLogPluginLogLevel(logLevelExtractor))
}
var discardRegex = regexp.MustCompile("wabt.hpp:.*misaligned reference")
var toInfoRegex = regexp.MustCompile("(" +
strings.Join([]string{
"net_plugin.cpp:.*Closing connection to:",
"controller.cpp:.*(No existing chain state or fork database|Initializing new blockchain with genesis state)",
"platform_timer_accurac:.*Checktime timer",
}, "|") +
")")
func logLevelExtractor(in string) zapcore.Level {
if discardRegex.MatchString(in) {
return logplugin.NoDisplay
}
if toInfoRegex.MatchString(in) {
return zap.InfoLevel
}
groups := logLevelRegex.FindStringSubmatch(in)
if len(groups) <= 2 {
return zap.DebugLevel
}
switch groups[2] {
case "info":
return zap.InfoLevel
case "warn":
return zap.WarnLevel
case "error":
return zap.ErrorLevel
default:
return zap.DebugLevel
}
}