You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're using a logging library in main code, and to show application log in test code, we redirect it via following code (in a file named util_test.go).
// a io.WriteCLoser implementation that will direct data into testing.T.Logf(),// aim to use in test functions to print relevant log entries for each test case.// The log will only be shown if test fails, or -test.v is used.typetestingLogOutputstruct {
t*testing.T
}
func (output*testingLogOutput) Close() error { returnnil }
func (output*testingLogOutput) Write(p []byte) (nint, errerror) {
s:=string(p)
s=strings.TrimSpace(s)
output.t.Log(s)
returnlen(p), nil
}
funcnewTestLogWriter(t*testing.T) io.WriteCloser {
return&testingLogOutput{t: t}
}
It's nice that relevant log entries will be show per for each test case. But t.Log will always print the line number of file where it is called, and for our use case, it's always the same:
What version of Go are you using (
go version
)?Feature request: make
t.Log
output configurable.We're using a logging library in main code, and to show application log in test code, we redirect it via following code (in a file named
util_test.go
).It's nice that relevant log entries will be show per for each test case. But
t.Log
will always print the line number of file where it is called, and for our use case, it's always the same:Anyway to customize
t.Log
output? If it's not built-in yet, do you think it's worth a patch?The text was updated successfully, but these errors were encountered: