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

all: avoid passing logger to methods #1968

Open
wants to merge 6 commits into
base: stage
Choose a base branch
from
Open

Conversation

nkryuchkov
Copy link
Contributor

@nkryuchkov nkryuchkov commented Dec 28, 2024

as per title

Copy link
Contributor

@y0sher y0sher left a comment

Choose a reason for hiding this comment

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

gj, we should do this code-wide :)

@nkryuchkov nkryuchkov changed the title network/p2p: avoid passing logger to p2p methods all: avoid passing logger to p2p methods Jan 21, 2025
@nkryuchkov nkryuchkov changed the title all: avoid passing logger to p2p methods all: avoid passing logger to methods Jan 21, 2025
@nkryuchkov nkryuchkov marked this pull request as ready for review January 21, 2025 20:55
@nkryuchkov
Copy link
Contributor Author

@y0sher I did it code-wide, although I might have missed something. Anyway, we'll be able to fix leftovers if we find them. Please review it again

Copy link

codecov bot commented Jan 21, 2025

Copy link
Contributor

@oleg-ssvlabs oleg-ssvlabs left a comment

Choose a reason for hiding this comment

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

Awesome, these are certainly great changes!
An alternative approach could be having a separate logger package that encapsulates Zap and is loaded as a package (rather than being injected through a constructor or function/method).
Something like this:

package logger

import "go.uber.org/zap"

var logger = zap.L()

func Info(msg string, fields ...zap.Field) {
	logger.Info(msg, fields...)
}

And the usage:

package main

import "github.com/ssvlabs/utils/logger"

func main() {
	logger.Info("Hello, world!")
}

However, if we want to have named loggers at the object level or loggers with additional properties applicable to all log records, we would likely still need to inject it through a constructor.

Copy link
Contributor

@iurii-ssv iurii-ssv left a comment

Choose a reason for hiding this comment

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

Good stuff!

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.

6 participants