From 6de84c363f38cb791f5c67a51d21ef667108ef7d Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 19 Oct 2023 20:23:48 +0200 Subject: [PATCH] cmd/geth: fix fileout-test by avoiding formatter-bug --- cmd/geth/logging_test.go | 13 +------------ cmd/geth/logtestcmd.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/cmd/geth/logging_test.go b/cmd/geth/logging_test.go index 534059971e..2264621298 100644 --- a/cmd/geth/logging_test.go +++ b/cmd/geth/logging_test.go @@ -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 { diff --git a/cmd/geth/logtestcmd.go b/cmd/geth/logtestcmd.go index 77d4417b2d..3630324031 100644 --- a/cmd/geth/logtestcmd.go +++ b/cmd/geth/logtestcmd.go @@ -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")