Navigation Menu

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
Closed

Comments

@rogpeppe
Copy link
Contributor

rogpeppe 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{})
@gopherbot gopherbot added this to the Proposal milestone Feb 8, 2018
@FiloSottile
Copy link
Contributor

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
Copy link
Contributor

rsc 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 as completed 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.
Projects
None yet
Development

No branches or pull requests

4 participants