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

proposal: testing: provide a way to log a line without a source location #23747

Closed
rogpeppe opened this issue Feb 8, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@rogpeppe
Copy link
Contributor

commented Feb 8, 2018

There's no way to log a line without also including source information of a caller of Log.

When hooking logger implementations up *testing.T so that log messages can be directly associated with a test (particularly important when running parallel tests), the source line is almost always noise, as one of the callers of t.Log will be a function in the logging package, which cannot call Helper. Also the logger
implementation will usually be in a position to add its own annotation.

Unnecessary noise can often be a significant barrier to quick comprehension of test output.

We propose that a new method be added to *testing.T, *testing.B and testing.TB:

// LogClean logs the given arguments similarly to Log, but does
// not decorate the line with file and line number information.
func (t *T) LogClean(args ...interface{})

@rogpeppe rogpeppe added the Proposal label Feb 8, 2018

@gopherbot gopherbot added this to the Proposal milestone Feb 8, 2018

@FiloSottile

This comment has been minimized.

Copy link
Member

commented Feb 10, 2018

For the same reason, I often wanted a io.Writer bound to the test output (and had to implement a bad one on top of T.Log). Sounds like that might be a better solution because it also avoids spurious newlines, and plugs right into log.SetOutput.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Mar 5, 2018

I understand your point but in this case it seems like the best choice is to print another file:line after with what you want to indicate. New API for this doesn't seem warranted.
Note that you could also just log all your output to a buffer and print it out at the end as a multiline t.Log, and then you only get one prefix at the start.

@rsc rsc closed this Mar 5, 2018

@golang golang locked and limited conversation to collaborators Mar 5, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.