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

vsp: Don't use a global logger. #2256

Merged
merged 2 commits into from
Jun 30, 2023
Merged

vsp: Don't use a global logger. #2256

merged 2 commits into from
Jun 30, 2023

Conversation

jholdstock
Copy link
Member

Keep references to the logger inside the VSP client rather than using a global reference.

Keep references to the logger inside the VSP client rather than using a global
reference.
@@ -59,7 +61,7 @@ type Config struct {
Params *chaincfg.Params
}

func New(cfg Config) (*Client, error) {
func New(cfg Config, log slog.Logger) (*Client, error) {
Copy link
Member

Choose a reason for hiding this comment

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

do you think it would make more sense to provide the logger in the config? and if it's nil, either don't log anything (probably the best default) or have some default logger to stdout or something (i'm less thrilled by this idea)

Copy link
Member Author

Choose a reason for hiding this comment

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

I added it here to avoid adding it in every place where a vsp.Config instance is created (there are a lot of them - server.go is peppered).

Just to explain my reasoning...

Personally I don't view a logger as logically being a config item. I view config as a set of static values which tweak/toggle various behaviours of the component they are passed in to. The values in config may be mandatory or they may have defaults.

A logger is an independent component which implements its own behaviour (and probably has its own config internally). I put logger in the same "not config" category as database/RPC connections, caches, clocks, random number generators. Distinct from config, I'd consider these to be non-optional. They are typically fundamental things your component needs to do its job.

That said, this is all pretty subjective. I'm happy to change it if you like, just let me know what your preferred solution is.

Perhaps we could default to slog.Disabled if you want logger to be optional?

Copy link
Member

Choose a reason for hiding this comment

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

it's fine as is, just wanted to run the idea past you for your opinion

@@ -95,6 +96,7 @@ type feePayment struct {
timerMu sync.Mutex
timer *time.Timer

log slog.Logger
Copy link
Member

Choose a reason for hiding this comment

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

the fee payment holds a pointer to the client, we can access the logger through that instead of copying the interface value for every fee payment. i don't think there is any reason that one fee payment should use a different logger from any other, and it reduces the pressure on the GC a small bit since it's less pointers that it needs to follow.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've made the suggested change.

I included logger in feePayment because in future I want to try and remove the circular reference between Client and feePayment, but that can wait for another day.

Use the existing pointer in Client to access the logger, rather than keeping a
separate (duplicated) pointer in feePayment.
@jrick jrick merged commit b1ef225 into decred:master Jun 30, 2023
2 checks passed
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.

2 participants