Skip to content

Commit

Permalink
cmd/geth: fix fileout-test by avoiding formatter-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Oct 19, 2023
1 parent b75f045 commit 6de84c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
13 changes: 1 addition & 12 deletions cmd/geth/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,7 @@ func TestFileOut(t *testing.T) {
path = fmt.Sprintf("%s/test_file_out-%d", os.TempDir(), rand.Int63())
)
t.Cleanup(func() { os.Remove(path) })
/*
If terminal/logfmt format is used, then this test fails -- apparently the file-, or stream-, or
multiplexhandler somehow treats records with duplicate keys differently, adding an extra space
on the log output between the two keys.
Using the `json` format cheats and gets around this, since json cannot represent duplicate keys.
logging_test.go:153: have vs want:
"repeated-key foo=once foo=twice\nINFO [10-19|14:42:23.554] log "
"repeated-key foo=once foo=twice\nINFO [10-19|14:42:23.554] log"
logging_test.go:154: file content wrong
*/
if want, err = runSelf(fmt.Sprintf("--log.file=%s", path), "--log.format=json", "logtest"); err != nil {
if want, err = runSelf(fmt.Sprintf("--log.file=%s", path), "logtest"); err != nil {
t.Fatal(err)
}
if have, err = os.ReadFile(path); err != nil {
Expand Down
11 changes: 8 additions & 3 deletions cmd/geth/logtestcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ func logTest(ctx *cli.Context) error {
{ // Miscellaneous json-quirks
// This will check if the json output uses strings or json-booleans to represent bool values
log.Info("boolean", "true", true, "false", false)
// Handling of duplicate keys ?
log.Info("repeated-key", "foo", "once", "foo", "twice")
// Handling of duplicate keys.
// This is actually ill-handled by the current handler: the format.go
// uses a global 'fieldPadding' map and mixes up the two keys. If 'alpha'
// is shorter than beta, it sometimes causes erroneous padding -- and what's more
// it causes _different_ padding in multi-handler context, e.g. both file-
// and console output, making the two mismatch.
log.Info("repeated-key", "foo", "alpha", "foo", "beta")
}
{ //
{ // loglevels
log.Debug("log at level debug")
log.Trace("log at level trace")
log.Info("log at level info")
Expand Down

0 comments on commit 6de84c3

Please sign in to comment.