-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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: test for logging-output #28373
Conversation
Yeah, it's unfortunate that there's no spec-defined ordering for json keys. |
Oh ISTR that the golang json lib we use does have deterministic ordering. But the actual timestamp will land on different indexes on each line, so although it may be deterministic, it's not as simple as the other two where I can just blank out certain byte-indexes. |
slog: ours: The ordering is different (disregarding the inconsistencies in key names/values which I'm trying to fix). |
so doing it this way might be too restrictive for json only b/c of the lack of defined ordering for keys. |
Yes, for json we need something else. On the other hand, |
One thing I noticed while doing the log-tests , is that if we use We could use a custom "both terminal and file" handler like this: func PipeHandler(fmtr Format, terminal io.Writer, path string) (Handler, error) {
f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return nil, err
}
return FuncHandler(func(r *Record) error {
out := fmtr.Format(r)
terminal.Write(out)
_, err := f.Write(out)
return err
}), nil
} But it doesn't seem worth it to optimize the log stuff now, since we're moving to |
The double-output-processing is now fixed in this PR. |
Adding this for triage discussion: it adds another command, |
cmd/geth/logtestcmd.go
Outdated
log.Info("test", "bar", "short", "a", "aligned right") | ||
} | ||
{ | ||
// This sequence of logs should be output with alignment, so each field becoems a column. |
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 sequence of logs should be output with alignment, so each field becoems a column. | |
// This sequence of logs should be output with alignment, so each field becomes a column. |
triage discussion: look into using a |
It's now disabled unless the tag
and
|
btw @jwasinger -- I don't think changing |
This PR is a bit in preparation for the slog work in ethereum#28187 . Our current test re logging mostly test the internals, but we have no real end-to-end test of the logging output. This PR introduces a simple reexec-based log tester. This also relies upon a special mode in geth, which can be made to eject a set of predefined log messages (only available if the build-tag `integrationtests` is used e.g. go run --tags=integrationtests ./cmd/geth --log.format terminal logtest While working on this, I also noticed a quirk in the setup: when geth was configured to use a file output, then two separate handlers were used (one handler for the file, one handler for the console). Using two separate handlers means that two formatters are used, thus the formatting of any/all records happened twice. This PR changes the mechanism to use two separate io.Writers instead, which is both more optimal and fixes a bug which occurs due to a global statefulness in the formatter.
This reverts commit 6a1deae.
This reverts commit 6a1deae.
This PR is a bit in preparation for the slog work in ethereum#28187 . Our current test re logging mostly test the internals, but we have no real end-to-end test of the logging output. This PR introduces a simple reexec-based log tester. This also relies upon a special mode in geth, which can be made to eject a set of predefined log messages (only available if the build-tag `integrationtests` is used e.g. go run --tags=integrationtests ./cmd/geth --log.format terminal logtest While working on this, I also noticed a quirk in the setup: when geth was configured to use a file output, then two separate handlers were used (one handler for the file, one handler for the console). Using two separate handlers means that two formatters are used, thus the formatting of any/all records happened twice. This PR changes the mechanism to use two separate io.Writers instead, which is both more optimal and fixes a bug which occurs due to a global statefulness in the formatter.
This PR is a bit in preparation for the slog work in ethereum#28187 . Our current test re logging mostly test the internals, but we have no real end-to-end test of the logging output. This PR introduces a simple reexec-based log tester. This also relies upon a special mode in geth, which can be made to eject a set of predefined log messages (only available if the build-tag `integrationtests` is used e.g. go run --tags=integrationtests ./cmd/geth --log.format terminal logtest While working on this, I also noticed a quirk in the setup: when geth was configured to use a file output, then two separate handlers were used (one handler for the file, one handler for the console). Using two separate handlers means that two formatters are used, thus the formatting of any/all records happened twice. This PR changes the mechanism to use two separate io.Writers instead, which is both more optimal and fixes a bug which occurs due to a global statefulness in the formatter.
This PR is a bit in preparation for the
slog
work in #28187 .Our current test re logging mostly test the internals, but we have no real end-to-end test of the logging output. This PR introduces a simple reexec-based log tester. This also relies upon a special mode in geth, which can be made to eject a set of predefined log messages.
e.g.
geth --log.format terminal logtest
.If we decide to use this approach, we can remove many other tests, e.g. in
format_test.go
. With this approach, we can swap out our internal logging engine but not actually modfiy the tests (except modifying the expected outputs, if we want to).While working on this, I also noticed a quirk in the setup: when geth was configured to use a file output, then two separate handlers were used (one handler for the file, one handler for the console). Using two separate handlers means that two formatters are used, thus the formatting of any/all records happened twice. This PR changes the mechanism to use two separate
io.Writer
s instead, which is both more optimal and fixes a bug which occurs due to a global statefulness in the formatter.One annoying thing is that my approach works for
terminal
andlogfmt
, but notjson
, since locating and censoring the json timestamp is not as trivial.