Skip to content

Conversation

taylorchu
Copy link
Contributor

This reverts 0baad4d.

Setting a global log level in an initializer causes unwanted side effects in many cases. User who needs this should do log.SetLevelByString in main program only.

@taylorchu
Copy link
Contributor Author

@taylorchu
Copy link
Contributor Author

Another option will be having an user-provided logger. Since go community does not currently have a consensus on logger interface, this might not be wanted.

@siddontang
Copy link
Collaborator

Hi @taylorchu

I remember that some users meet the log info problem, so they want to control through configuration.

Maybe we can try:

if cfg.LogLevel != "" { log.SetLevelByString(cfg.LogLevel) }

So if the user set a log level config, he/she can use it.

@taylorchu
Copy link
Contributor Author

taylorchu commented Sep 26, 2017

If that is the problem, then setting log level there is not a good solution. Imagine that you create NewBinlogSyncer with "info" and "error" log level. You will expect that one syncer has log level of info, and the other has log level of error. However, the code we have now will only honor the BinlogSyncer of the latter call.

This gets worse if you use NewBinlogSyncer with goroutines. The logger is not only a global state, but that state is controlled by a nondeterministic function call order.

@siddontang
Copy link
Collaborator

Yes @taylorchu

IMO, I don't like go-mysql contains any log. But the missing log is hard for us to locate problems sometimes. Maybe a log interface is better, but Go doesn't supply a standard way sadly.

What is your opinion?

@taylorchu
Copy link
Contributor Author

type StdLogger interface { Print(...interface{}) Printf(string, ...interface{}) } 

Many go logger libraries support this interface, and that includes ngaut/log and logrus.

By default the package's logger uses stdlib logger, and it should be settable.

@siddontang
Copy link
Collaborator

Good idea, but I want to use different log level, maybe I can define a log interface like https://github.com/grpc/grpc-go/blob/master/grpclog/loggerv2.go#L30.

If the user doesn't pass a logger to go-mysql, we will use a NoopLogger which does nothing by default.

@taylorchu
Copy link
Contributor Author

Is there a use case to have different log level within this package github.com/siddontang/go-mysql?

For our usage, we really don't care. Every log line here is equivalent to "DEBUG" level.

@siddontang
Copy link
Collaborator

maybe needed. I will merge this PR now, thanks, @taylorchu.

Maybe it is better to support passing a Logger, I will do it later.

@siddontang siddontang merged commit 8e139d8 into go-mysql-org:master Sep 30, 2017
@taylorchu taylorchu mentioned this pull request Oct 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants