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
Tests that have to create a *log.Logger do not (at least not out of the box) get to take advantage of testing's T.Log and the nice features that come with it.
This implies test writers have to either wrap T.Log up to make it implement io.Writer somehow and pass that into log.New(tlogger, "", 0), or discard their logs all together (e.g., log.New(ioutil.Discard, "", 0)).
Solution
Have testing.T and testing.B implement io.Writer.
This will allow developers to simply create a log.Logger by doing log.New(t, "", 0). It would also be compatible with most other logging libraries.
The text was updated successfully, but these errors were encountered:
@dpinela That works as long as the developer has control over the interface. If however they are using a dependency that requires a *log.Logger, then that won't work for them.
Line-at-a-time logging is not the same as a Write method (Writes are not guaranteed to be aligned with any useful boundary, certainly not lines). But this is not about Write at all. It's about log.Logger, which is/was #22513. Closing as duplicate.
Problem
Tests that have to create a
*log.Logger
do not (at least not out of the box) get to take advantage of testing's T.Log and the nice features that come with it.This implies test writers have to either wrap
T.Log
up to make it implementio.Writer
somehow and pass that intolog.New(tlogger, "", 0)
, or discard their logs all together (e.g.,log.New(ioutil.Discard, "", 0)
).Solution
Have
testing.T
andtesting.B
implement io.Writer.This will allow developers to simply create a
log.Logger
by doinglog.New(t, "", 0)
. It would also be compatible with most other logging libraries.The text was updated successfully, but these errors were encountered: