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

testlog: sub-logger output is lost #31533

Closed
protolambda opened this issue Mar 31, 2025 · 2 comments · Fixed by #31539
Closed

testlog: sub-logger output is lost #31533

protolambda opened this issue Mar 31, 2025 · 2 comments · Fixed by #31539
Assignees
Labels

Comments

@protolambda
Copy link
Contributor

protolambda commented Mar 31, 2025

I was debugging some internals, and the test-logger was silently hiding important information from a sub-logger.

We can make the bufHandler not buffered, and surface the data synchronously. The test logger already flushes after every single log call, so there's no point in not doing that.

On a related note, the flush() after a crit never happens, because the inner crit logger is going to os.Exit(1), thus omitting critical info (originally found by @samlaf )

System information

Latest master branch.

Expected behaviour

    testlog_test.go:13: INFO [03-31|13:28:01.130] Visible                                  
    testlog_test.go:14: INFO [03-31|13:28:01.130] Hide and seek      foobar=123
    testlog_test.go:15: INFO [03-31|13:28:01.130] Also visible                             

Actual behaviour

    testlog_test.go:13: INFO [03-31|13:28:01.130] Visible                                  
    testlog_test.go:15: INFO [03-31|13:28:01.130] Also visible                      

Steps to reproduce the behaviour

Add a testlog_test.go with basic test:

package testlog

import (
	"testing"

	"github.com/ethereum/go-ethereum/log"
)

func TestLogging(t *testing.T) {
	l := Logger(t, log.LevelInfo)
	subLogger := l.New("foobar", 123)

	l.Info("Visible")
	subLogger.Info("Hide and seek") // not visible due to sub buffer never being flushed
	l.Info("Also visible")

	t.Log("flushed: ", l.Handler().(*bufHandler).buf)
	t.Log("remaining: ", subLogger.Handler().(*bufHandler).buf)
	// horrible hack to manually bring back the expected log data
	l.Handler().(*bufHandler).buf = subLogger.Handler().(*bufHandler).buf
	l.(*logger).flush()
}
=== RUN   TestLogging
    testlog_test.go:13: INFO [03-31|13:30:10.246] Visible                                  
    testlog_test.go:15: INFO [03-31|13:30:10.246] Also visible                             
    testlog_test.go:17: flushed:  []
    testlog_test.go:18: remaining:  [{2025-03-31 13:30:10.246453737 +0200 CEST m=+0.000212631 Hide and seek INFO 5598664 [{ {[] 0 <nil>}} { {[] 0 <nil>}} { {[] 0 <nil>}} { {[] 0 <nil>}} { {[] 0 <nil>}}] 0 []}]
    testlog_test.go:21: INFO [03-31|13:30:10.246] Hide and seek                            
--- PASS: TestLogging (0.00s)
PASS

Note: the foobar=123 is still lost for some reason.

Backtrace

N/A

@jwasinger jwasinger self-assigned this Mar 31, 2025
@jwasinger
Copy link
Contributor

What version of Geth is this using? It doesn't appear compatible with our current log package.

@protolambda
Copy link
Contributor Author

ffa315f7460b6f050e89b63ca63876d974fb19bf (ffa315f) is the exact commit.

And it's the internal/testlog package that the test applies to, not the log package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants