Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

WithLogger connOption and Conn.logInfo bool #170

Merged
merged 2 commits into from
Nov 17, 2017
Merged

Conversation

nsd20463
Copy link
Contributor

@nsd20463 nsd20463 commented Aug 9, 2017

WithLogger connection option allow setting the logger right away, rather than racing with the connection's goroutine.

WithLogInfo connection option allows silencing the informational messages which otherwise get logged to stderr (by default).

This allows setting the logger as the connection is created, rather
than racing to call SetLogger while the connection's goroutine might
already be logging a successful (or failed) connection.

In addition using WithLogger works around the data race between SetLogger
and the connection's goroutine.

The data race is NOT fixed by this commit. AFAICS doing so is a nontrivial.
Every access to conn.logger would need to be atomic.
By default it is enabled for backwards compatability, but
by setting logInfo=false you can have silence on stderr
when no errors are in fact occurring.

This is desireable for commandline tools, where the convention
I prefer is that silence indicates success.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 80.916% when pulling f0d9587 on nsd20463:logging into 8ac67fa on samuel:master.

@rboyer
Copy link

rboyer commented Nov 17, 2017

I'm running across the same race condition and this PR totally fixes it. Any hope of merging it in?

@samuel
Copy link
Owner

samuel commented Nov 17, 2017

Oh yeah, thanks for the change.

@samuel samuel merged commit fb09205 into samuel:master Nov 17, 2017
@nsd20463 nsd20463 deleted the logging branch December 2, 2017 01:47
jeffbean pushed a commit to jeffbean/go-zookeeper that referenced this pull request Dec 28, 2018
* add WithLogger connOption

This allows setting the logger as the connection is created, rather
than racing to call SetLogger while the connection's goroutine might
already be logging a successful (or failed) connection.

In addition using WithLogger works around the data race between SetLogger
and the connection's goroutine.

The data race is NOT fixed by this commit. AFAICS doing so is a nontrivial.
Every access to conn.logger would need to be atomic.

* add Conn.logInfo bool controling informational messages

By default it is enabled for backwards compatability, but
by setting logInfo=false you can have silence on stderr
when no errors are in fact occurring.

This is desireable for commandline tools, where the convention
I prefer is that silence indicates success.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants