-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
refactor(log): associate test logger with testing.T instance #15261
Conversation
Rename from NewTestingLogger to NewTestLogger, as many tests will require this -- the latter name is shorter and a more common name. Instead of a globally shared logger, use zerolog's TestWriter to associate loggers with individual tests. This breaks the log module's direct dependency on the testing package, as we no longer inspect the testing package's Verbose function. When running go test -v, you will still see all logging messages, but they will be associated with the test using that logger instance. When running just go test without the -v flag, you will only see logging messages on failed tests (the default behavior of calls to t.Log). Also server/mock.SetupApp into the test package, so that the non-test mock package does not have a direct dependency on testing.
There were several tests using log.NewLogger, which would direct output to stdout. While this somewhat works in tests, the test logger is a better match for the intent -- it uses (*testing.T).Logf so that the output is hidden by default, shown on test failure, or always shown when opting in through go test -v. There were more tests in cosmosvisor that called NewLogger, but I didn't touch those because of their apparent complexity in setting up buffered pipes and so on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm!
@@ -154,6 +154,9 @@ require ( | |||
nhooyr.io/websocket v1.8.6 // indirect | |||
) | |||
|
|||
// Short-lived replace for an outstanding PR of log. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we do now (for tools actively in dev) is to use the commit of the PR to create a pseudo version, so it limits the number of PRs.
We have a script to update it everywhere easily ./scripts/go-update-dep-all.sh cosmossdk.io/log@commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one got forgotten I think.
x/upgrade/go.mod
Outdated
@@ -175,6 +175,9 @@ require ( | |||
sigs.k8s.io/yaml v1.3.0 // indirect | |||
) | |||
|
|||
// Short-lived replacement for an outstanding log PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
Description
This PR has two commits: the first refactors
NewTestLogger
to accept atesting.T
, and the next replaces widespread test usage oflog.NewLogger()
withlog.NewTestLogger(t)
.The primary advantage of a logger instance associated with a single test, is that logging is captured by default, but only shown per test's failure.
You will still see all the test logs when running with
go test -v
, but you won't need to re-run a failing test with-v
in order to see associated logs.TODO: after this PR is merged, remove replace statements in a few go.mod files.
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
added!
to the type prefix if API or client breaking changeprovided a link to the relevant issue or specificationfollowed the guidelines for building modulesCHANGELOG.md
updated the relevant documentation or specificationReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change