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

feat: add pvm logging #271

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: add pvm logging #271

wants to merge 1 commit into from

Conversation

danielvladco
Copy link
Member

No description provided.

@danielvladco danielvladco requested a review from a team February 20, 2025 09:47
// wrap mutator with logging
var m polkavm.Mutator = i
if i.log != nil {
m = NewLogger(i, i.log)
Copy link
Contributor

Choose a reason for hiding this comment

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

Creating a new logger every step?

@@ -0,0 +1,578 @@
package interpreter
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about the whole approach. Decorating every function seems wrong. Are we going to do this everywhere? Seems to me it's better just add logging in the Instance functions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting, I actually prefer this approach because it abstracts logging into it's own file instead of polluting the codebase with logs and can be easily plugged in and out when necessary without refactoring a lot. I think going forward we need to discuss this more thoroughly with the team and go with a convention that the majority prefers

Copy link
Contributor

Choose a reason for hiding this comment

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

So for every function we have in the repo we are going to create a new struct that decorates with logging?

Copy link
Member Author

Choose a reason for hiding this comment

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

of course not :) this pattern is used with interfaces, usually for services to track the incoming and outgoing args. For this project we don't really use interfaces for this purpose except for the Mutator interface in pvm so I understand your concern

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also not too sure about this approach, seems clearer to me if the logging is just mixed in, but that might be just me. :)

@@ -43,6 +49,8 @@ type Instance struct {
jumpTable []uint64 // j
bitmask jam.BitSequence // k
basicBlockInstructions map[uint64]struct{} // ϖ

log *zerolog.Logger
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels wrong. Imo the instance should not care if we are logging or not. Is the idea that we save on performance to run without zerolog, compared to running with Disabled?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is necessary in order to be able to inject the logger inside the instance, how else are we supposed to access the logger? use a global instance?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I should have explained properly. I mean the whole approach, putting a pointer here, so later you have to check if i.log != nil and change the behaviour. Zerolog is designed to not be used as pointer and just log stuff, unless you silence it. It's also safe that way that it works as a no-op logger if you instance has no logger passed to it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I didn't know this library is not expecting to pass the logger instance as a pointer, most loggers that I worked with are expecting a pointer


func WithLogger(log zerolog.Logger) Option {
return func(i *Instance) {
i.log = &log
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pointer to a copy of the Logger not the actual Logger.

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.

3 participants