Hey all, new to Go here but am starting to work on some new services which use it and got a question on testing and logging. Has anyone run into having to test log output with go or know of some resources that go into this with good practices etc. I've looked quite a bit online but haven't found anything concrete. Part of the unit testing we like to add in previous projects (mostly in Python) is that we are getting the expected log output.
评论:
kpurdon:
j_d_q:I'm not sure stdlib log provides anything. Logrus provides https://github.com/sirupsen/logrus#testing ... testing log output seems a bit excessive to me though.
Out of curiosity what value do you get from testing expected log outputs? I could understand testing audit streams or something like that, but just straight logs?
I imagine you could overwrite os.Stdout and os.Stderr to your own buffers
