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

removing/disabling logging #60

Closed
theckman opened this issue Jun 4, 2015 · 2 comments
Closed

removing/disabling logging #60

theckman opened this issue Jun 4, 2015 · 2 comments

Comments

@theckman
Copy link
Contributor

theckman commented Jun 4, 2015

I wanted to open an issue for this issue to get feedback before going further and starting to modify the code in preparation for a PR.

When using the library, it log failures and the like by default:

2015/06/04 21:07:54 Failed to connect to 127.0.0.1:2181: dial tcp 127.0.0.1:2181: connection refused

Without setting the writer for all logging to something that isn't stdout, there doesn't appear to be a way to disable this logging. Is there a reason logging was enabled in the library by default?

@theckman theckman closed this as completed Jun 4, 2015
@theckman theckman reopened this Jun 4, 2015
@samuel
Copy link
Owner

samuel commented Jun 4, 2015

I believe there's 3 instance of logging in the server: failed to connect to server, failed to set previous watches, and a catch all for unexpected errors (which likely point to bigger issues).

One alternative is to turn off logging and use exported metrics so that any existing alerting infrastructure can be used (e.g. failed to connect N times in M seconds).. this likely should be added anyway regardless of logging.

Do you think it would be ok if you could pass in a custom logger to the client (func (c *Conn) SetLogger(Logger)) conforming to an interface like:

type Logger interface {
    Printf(format string, v ...interface{})
}

and by default the stdlib log would be used. Then could override it to disable logging entirely or reroute to a more appropriate place (perhaps syslog if using it).

@theckman
Copy link
Contributor Author

theckman commented Jun 5, 2015

I think that would make sense to me. Then have an unexported struct field for the Logger. To avoid breaking the old way, we could default to setting up a logger that has the same behavior as now.

theckman added a commit to theckman/go-zookeeper that referenced this issue Jun 5, 2015
By adding this Logger interface, and by fulfilling the interface with a function that has no body, you can silence the log messages from the *zk.Conn instance. The `Connect()` and `ConnectWithDialer()` functions both set the logger up by default to log to `Stderr`.

Fixes samuel#60.
theckman added a commit to theckman/go-zookeeper that referenced this issue Jun 5, 2015
By adding this Logger interface, and by fulfilling the interface with a function that has no body, you can silence the log messages from the *zk.Conn instance. The `Connect()` and `ConnectWithDialer()` functions both set the logger up by default to log to `Stderr`.

Fixes samuel#60.
@samuel samuel closed this as completed in #61 Jun 5, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants