Hello!

I'm working on logging in Kubernetes. One of the problems there is that all 
log output goes through a global logger in the k8s.io/klog package, which 
writes to stderr. When such code runs in a unit test, that additional 
output is not associated with the currently running unit test, so the 
output of `go test` for a failed test case is usually not helpful. It gets 
even worse when running tests in parallel.

I have a proposal pending for Kubernetes for doing logging via a 
go-logr/logr.Logger and how to pass that logger instance around through the 
code base. During tests, each test function then can create such a Logger 
that writes via t.Log and `go test` output becomes more useful. The actual 
code that goes into binaries is the same, it just uses different Logger 
implementations. The downside is that tests have to be modified to set up 
such per-test log output.

I don't see any other way of doing that, though, because the t instance of 
a test is by definition specific to each test function and therefore only 
that function can create the logger and then pass it on. If it was done by 
some kind of test driver, then there would be no way to pass the right 
logger into a `func TestFoo(t *testing.T)`.

How are other projects dealing with this? Is "normal" log output ignored 
and only log output from test code that gets the t parameter is used?

Thanks, Patrick


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/94d47fc2-6ee2-4c7f-9a21-26ff65acda30n%40googlegroups.com.

Reply via email to