-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(logging)_: switch to zap.Logger as central logger #6025
base: feat/categorized-logging
Are you sure you want to change the base?
Conversation
Jenkins BuildsClick to see older builds (47)
|
980b08f
to
0b320e3
Compare
c6ca8b4
to
0aca460
Compare
0aca460
to
30da93f
Compare
Set zap.Logger as the primary logger for status-go. All geth logs are now proxied through zap.Logger. closes: #6029
30da93f
to
282fcc1
Compare
func lvlFromString(lvlString string) (zapcore.Level, error) { | ||
switch strings.ToLower(lvlString) { | ||
case "trace", "trce": | ||
return zapcore.DebugLevel, nil // zap does not have a trace level, using DebugLevel as closest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should skip trace
messages. It will pollute debug logs too much.
|
||
buffer.Reset() | ||
log.Info("should be printed") | ||
require.Regexp(t, `INFO\s+'INFO\s*\[.*\]\s*should be printed '`, buffer.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is INFO
duplicated in the log message? :think
@@ -46,7 +45,6 @@ const ( | |||
var ( | |||
configFiles configFlags | |||
logLevel = flag.String("log", "", `Log level, one of: "ERROR", "WARN", "INFO", "DEBUG", and "TRACE"`) | |||
logWithoutColors = flag.Bool("log-without-color", false, "Disables log colors") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better to keep the flag, but deprecate it. I'm not sure of all usages of our cmd
s.
Or ensure that it's not used anywhere. And mark the commit as a breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
func defaultEncoder() zapcore.Encoder { | ||
encoderConfig := zap.NewDevelopmentEncoderConfig() | ||
encoderConfig.EncodeTime = utcTimeEncoder(encoderConfig.EncodeTime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
if fileOpts.Filename != "" { | ||
if fileOpts.MaxBackups == 0 { | ||
|
||
if settings.File != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please invrert the condition, so that the shorter branch goes first?
@@ -73,8 +71,11 @@ func init() { | |||
|
|||
// nolint:gocyclo | |||
func main() { | |||
colors := terminal.IsTerminal(int(os.Stdin.Fd())) | |||
if err := logutils.OverrideRootLog(true, "ERROR", logutils.FileOptions{}, colors); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why color support removed?
@@ -46,7 +45,6 @@ const ( | |||
var ( | |||
configFiles configFlags | |||
logLevel = flag.String("log", "", `Log level, one of: "ERROR", "WARN", "INFO", "DEBUG", and "TRACE"`) | |||
logWithoutColors = flag.Bool("log-without-color", false, "Disables log colors") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -53,6 +53,14 @@ func (core *Core) Enabled(lvl zapcore.Level) bool { | |||
return core.level.Enabled(lvl) | |||
} | |||
|
|||
func (core *Core) Level() zapcore.Level { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we rename the file to zap_core.go?
handler := log.StreamHandler(buf, log.TerminalFormat(false)) | ||
require.NoError(t, enableRootLog("debug", handler)) | ||
log.Debug("hello") | ||
require.Contains(t, buf.String(), "logutils/logger_test.go:16") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will it contain the origin info after replaced with zap?
func OverrideRootLog(enabled bool, levelStr string, fileOpts FileOptions, terminal bool) error { | ||
if !enabled { | ||
disableRootLog() | ||
if settings.MobileSystem { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems we never set MobileSystem to true in frontend, do you know why we need this ? 🤔
closes: #6029
NOTE: It will require testing on both platforms.