Skip to content
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

Open
wants to merge 2 commits into
base: feat/categorized-logging
Choose a base branch
from

Conversation

osmaczko
Copy link
Contributor

@osmaczko osmaczko commented Nov 1, 2024

closes: #6029

NOTE: It will require testing on both platforms.

@status-im-auto
Copy link
Member

status-im-auto commented Nov 1, 2024

Jenkins Builds

Click to see older builds (47)
Commit #️⃣ Finished (UTC) Duration Platform Result
✖️ ec32ae5 #1 2024-11-01 18:45:39 ~4 min tests 📄log
✔️ ec32ae5 #1 2024-11-01 18:45:47 ~4 min windows 📦zip
✔️ ec32ae5 #1 2024-11-01 18:45:49 ~4 min macos 📦zip
✔️ ec32ae5 #1 2024-11-01 18:46:09 ~4 min tests-rpc 📄log
✔️ ec32ae5 #1 2024-11-01 18:46:24 ~5 min linux 📦zip
✔️ ec32ae5 #1 2024-11-01 18:46:43 ~5 min android 📦aar
✔️ ec32ae5 #1 2024-11-01 18:46:50 ~5 min ios 📦zip
✔️ ec32ae5 #1 2024-11-01 18:47:36 ~6 min macos 📦zip
✔️ aadc36d #2 2024-11-03 18:49:46 ~3 min windows 📦zip
✔️ aadc36d #2 2024-11-03 18:50:30 ~4 min tests-rpc 📄log
✔️ aadc36d #2 2024-11-03 18:50:56 ~4 min macos 📦zip
✔️ aadc36d #2 2024-11-03 18:51:25 ~5 min linux 📦zip
✔️ aadc36d #2 2024-11-03 18:51:41 ~5 min android 📦aar
✔️ aadc36d #2 2024-11-03 18:51:49 ~5 min ios 📦zip
✔️ aadc36d #2 2024-11-03 18:52:34 ~6 min macos 📦zip
✖️ aadc36d #2 2024-11-03 19:19:58 ~33 min tests 📄log
✖️ 980b08f #3 2024-11-03 21:46:59 ~1 min tests 📄log
✔️ 980b08f #3 2024-11-03 21:48:17 ~3 min windows 📦zip
✔️ 980b08f #3 2024-11-03 21:49:11 ~4 min tests-rpc 📄log
✔️ 980b08f #3 2024-11-03 21:49:41 ~4 min macos 📦zip
✔️ 980b08f #3 2024-11-03 21:50:06 ~5 min linux 📦zip
✔️ 980b08f #3 2024-11-03 21:50:20 ~5 min ios 📦zip
✔️ 980b08f #3 2024-11-03 21:50:26 ~5 min android 📦aar
✔️ 980b08f #3 2024-11-03 21:51:05 ~6 min macos 📦zip
✖️ 0b320e3 #4 2024-11-04 07:59:17 ~1 min tests 📄log
✔️ 0b320e3 #4 2024-11-04 08:00:00 ~2 min tests-rpc 📄log
✔️ 0b320e3 #4 2024-11-04 08:00:40 ~2 min windows 📦zip
✔️ 0b320e3 #4 2024-11-04 08:02:21 ~4 min macos 📦zip
✔️ 0b320e3 #4 2024-11-04 08:02:40 ~5 min linux 📦zip
✔️ 0b320e3 #4 2024-11-04 08:02:59 ~5 min android 📦aar
✔️ 0b320e3 #4 2024-11-04 08:04:22 ~6 min ios 📦zip
✔️ 0b320e3 #4 2024-11-04 08:05:29 ~7 min macos 📦zip
✖️ c6ca8b4 #5 2024-11-04 08:22:01 ~2 min tests-rpc 📄log
✖️ c6ca8b4 #5 2024-11-04 08:22:09 ~2 min tests 📄log
✔️ c6ca8b4 #5 2024-11-04 08:22:14 ~2 min windows 📦zip
✔️ c6ca8b4 #5 2024-11-04 08:23:53 ~4 min macos 📦zip
✔️ c6ca8b4 #5 2024-11-04 08:24:21 ~5 min linux 📦zip
✔️ c6ca8b4 #5 2024-11-04 08:24:41 ~5 min android 📦aar
✔️ c6ca8b4 #5 2024-11-04 08:25:27 ~6 min ios 📦zip
✔️ c6ca8b4 #5 2024-11-04 08:27:07 ~7 min macos 📦zip
✖️ 0aca460 #6 2024-11-04 09:15:04 ~1 min tests 📄log
✔️ 0aca460 #6 2024-11-04 09:16:19 ~2 min windows 📦zip
✔️ 0aca460 #6 2024-11-04 09:17:43 ~4 min tests-rpc 📄log
✔️ 0aca460 #6 2024-11-04 09:17:58 ~4 min macos 📦zip
✔️ 0aca460 #6 2024-11-04 09:18:49 ~5 min android 📦aar
✔️ 0aca460 #6 2024-11-04 09:18:59 ~5 min linux 📦zip
✔️ 0aca460 #6 2024-11-04 09:19:07 ~5 min ios 📦zip
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 30da93f #7 2024-11-04 09:21:47 ~2 min windows 📦zip
✔️ 30da93f #7 2024-11-04 09:23:18 ~4 min tests-rpc 📄log
✔️ 30da93f #7 2024-11-04 09:23:19 ~4 min macos 📦zip
✔️ 30da93f #7 2024-11-04 09:24:35 ~5 min linux 📦zip
✔️ 30da93f #7 2024-11-04 09:24:59 ~5 min ios 📦zip
✔️ 30da93f #7 2024-11-04 09:26:59 ~8 min android 📦aar
✔️ 30da93f #7 2024-11-04 09:43:56 ~14 min macos 📦zip
✖️ 30da93f #7 2024-11-04 09:51:55 ~33 min tests 📄log
✔️ 282fcc1 #8 2024-11-04 09:39:46 ~2 min windows 📦zip
✔️ 282fcc1 #8 2024-11-04 09:41:29 ~4 min macos 📦zip
✔️ 282fcc1 #8 2024-11-04 09:41:33 ~4 min tests-rpc 📄log
✔️ 282fcc1 #8 2024-11-04 09:42:14 ~5 min linux 📦zip
✔️ 282fcc1 #8 2024-11-04 09:42:52 ~5 min ios 📦zip
✔️ 282fcc1 #8 2024-11-04 09:45:22 ~8 min android 📦aar
✔️ 282fcc1 #8 2024-11-04 09:55:45 ~11 min macos 📦zip
✖️ 282fcc1 #8 2024-11-04 10:26:52 ~34 min tests 📄log

@osmaczko osmaczko force-pushed the feat/zap-logger-takes-control branch 2 times, most recently from c6ca8b4 to 0aca460 Compare November 4, 2024 09:13
@osmaczko osmaczko changed the title chore_: WIP chore(logging)_: switch to zap.Logger as central logger Nov 4, 2024
@osmaczko osmaczko linked an issue Nov 4, 2024 that may be closed by this pull request
@osmaczko osmaczko force-pushed the feat/zap-logger-takes-control branch from 0aca460 to 30da93f Compare November 4, 2024 09:18
Set zap.Logger as the  primary logger for status-go. All geth logs are
now proxied through zap.Logger.

closes: #6029
@osmaczko osmaczko force-pushed the feat/zap-logger-takes-control branch from 30da93f to 282fcc1 Compare November 4, 2024 09:36
@osmaczko osmaczko marked this pull request as ready for review November 4, 2024 09:38
@osmaczko osmaczko requested review from qfrank, igor-sirotin and a team November 4, 2024 09:38
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
Copy link
Collaborator

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())
Copy link
Collaborator

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")
Copy link
Collaborator

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 cmds.
Or ensure that it's not used anywhere. And mark the commit as a breaking change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls don't remove it,I like the colorful output. Especially, we will frequently use the status backend server now.
image


func defaultEncoder() zapcore.Encoder {
encoderConfig := zap.NewDevelopmentEncoderConfig()
encoderConfig.EncodeTime = utcTimeEncoder(encoderConfig.EncodeTime)
Copy link
Collaborator

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 != "" {
Copy link
Collaborator

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 {
Copy link
Contributor

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls don't remove it,I like the colorful output. Especially, we will frequently use the status backend server now.
image

@@ -53,6 +53,14 @@ func (core *Core) Enabled(lvl zapcore.Level) bool {
return core.level.Enabled(lvl)
}

func (core *Core) Level() zapcore.Level {
Copy link
Contributor

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")
Copy link
Contributor

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 {
Copy link
Contributor

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 ? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make zap.Logger a central logger
4 participants