Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Conversation

@jmank88
Copy link
Collaborator

@jmank88 jmank88 commented Sep 13, 2017

What does this do / why do we need it?

This change replaces global discard Logger variables with per-test instances.

We've developed a habit of using consolidated global vars to share discardLoggers between tests (log.New(ioutil.Discard, "", 0)). This seems logical since calls are effectively no-ops, but the internals of the Logger are still locking to serialize writes to ioutil.Discard, which creates unnecessary coupling and synchronization between tests that could otherwise be completely independent and/or parallel.

Copy link
Member

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have a helper func to do it, just so that the intent and pattern is entirely clear. makes it easy, too - just turn var discardLogger into func discardLogger() *log.Logger

@jmank88
Copy link
Collaborator Author

jmank88 commented Sep 14, 2017

let's have a helper func to do it, just so that the intent and pattern is entirely clear. makes it easy, too - just turn var discardLogger into func discardLogger() *log.Logger

Done

var (
discardLogger = log.New(ioutil.Discard, "", 0)
)
func discardLogger() *log.Logger {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about moving this to internal/test and exporting? That way it doesn't need to be defined.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kinda meh about that - tbh I was kinda meh about my original suggestion, but the idea of exporting it just makes it seem definitively unwise 😛

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care much about if we do it or not but out of curiosity what's wrong/unwise with exporting test.DiscardLogger() in our internal test package?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a really subjective thing, which is why i sorta hesitate about it in the first place, but to my mind, exporting jumps the line between an innocuous helper and a recommended pattern.

Copy link
Collaborator

@ibrasho ibrasho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sdboyer sdboyer merged commit 92657ba into golang:master Sep 18, 2017
@jmank88 jmank88 deleted the discard_logger branch September 18, 2017 11:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants