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

cmd/geth, internal/debug: get rid of by-default log config #28801

Merged
merged 1 commit into from Jan 12, 2024

Conversation

karalabe
Copy link
Member

@karalabe karalabe commented Jan 12, 2024

Initializing a default logger on package init is bad practice, because anything referencing the package will have this side effect. This specifically came up with the new simulated backend, which uses node/api, which pulls in the debug namespace, initing the logger. That's bad, as everything gets very verbose this way.

This PR gets rid of most of the initialization. It just leaves in initing the glogger value, so if someone uses the api handler without calling Setup, they don't end up with nil exceptions.

@karalabe karalabe added this to the 1.13.11 milestone Jan 12, 2024
@@ -51,9 +50,6 @@ func (c customQuotedStringer) String() string {
// logTest is an entry point which spits out some logs. This is used by testing
// to verify expected outputs
func logTest(ctx *cli.Context) error {
// clear field padding map
debug.ResetLogging()
Copy link
Contributor

Choose a reason for hiding this comment

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

We had to add this to have the log tests deterministic. Curious if it works without 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.

That's why I was asking how this thing is used? The only was I saw was running geth logtest, in which case there's nothing logging that would break 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.

There's no documentation on how to use this command, so I have no idea if I broke something or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

The tests will tell you if you did

Copy link
Contributor

Choose a reason for hiding this comment

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

 go test ./cmd/geth -tags integrationtests -run TestLogging

Copy link
Contributor

Choose a reason for hiding this comment

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

CI seems happy about it though :)

@fjl
Copy link
Contributor

fjl commented Jan 12, 2024

It's a bit strange to have a geth command that tests some log output. We could also just have this as a unit test or something.

@holiman
Copy link
Contributor

holiman commented Jan 12, 2024

It's a bit strange to have a geth command that tests some log output.

We don't, it is a command which spits out a predefined set of logs.

We could also just have this as a unit test or something.

We do (cmd/geth/logging_test.go:TestLogging)

@fjl
Copy link
Contributor

fjl commented Jan 12, 2024

Yeah I get it, but why is this a cmd/geth test and not a package log test.

@holiman
Copy link
Contributor

holiman commented Jan 12, 2024

Because it's testing the geth logging, it is not log-package specific.
It is testing the log arguments to geth, and geth's output.

@fjl
Copy link
Contributor

fjl commented Jan 12, 2024

Ahh OK!

@fjl
Copy link
Contributor

fjl commented Jan 12, 2024

The flags to geth will directly translate into log.Glogger settings though. So we could also move this test into internal/debug or package log? It wouldn't be testing the actual flags, but their Go method equivalents.

Looking at this test, I just really think this test should always run, not just manually. It's not great to have a larget bit of code that doesn't compile/run by default in CI.

@holiman
Copy link
Contributor

holiman commented Jan 12, 2024

Yes, but not without loss of test-coverage. So if we screw up geth logging output, or ability spit log output to file, we won't notice it. I added these tests which test the binary in order to ensure that we detect if we bork geth. I think it's a LOT better than a package-level test.

It's not great to have a larget bit of code that doesn't compile/run by default in CI.

We run it on CI

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

Seems good to me

@karalabe karalabe merged commit 43ba7d6 into ethereum:master Jan 12, 2024
1 of 3 checks passed
Dergarcon pushed a commit to specialmechanisms/mev-geth-0x2mev that referenced this pull request Jan 31, 2024
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.

None yet

3 participants