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

Register mysql default logger prior to mysql#NewConfig() #732

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

yhabteab
Copy link
Member

@yhabteab yhabteab commented Apr 8, 2024

Before:

2024-04-08T13:55:58.621+0200    WARN    database        Can't connect to database. Retrying     {"error": "driver: bad connection"}
2024-04-08T13:56:00.294+0200    WARN    database        Can't connect to database. Retrying     {"error": "dial tcp [::1]:3306: connect: connection refused"}
2024-04-08T13:56:40.352+0200    INFO    database        Reconnected to database {"after": "41.737475334s", "attempts": 10}
[mysql] 2024/04/08 14:03:19 connection.go:49: closing bad idle connection: EOF
[mysql] 2024/04/08 14:03:19 connection.go:49: closing bad idle connection: EOF

After:

2024-04-08T14:41:53.032+0200    DEBUG   database        [unexpected EOF]
2024-04-08T14:41:53.272+0200    DEBUG   database        [unexpected EOF]
2024-04-08T14:41:53.272+0200    WARN    database        Can't connect to database. Retrying     {"error": "driver: bad connection"}
2024-04-08T14:41:53.353+0200    DEBUG   database        [unexpected EOF]
2024-04-08T14:41:53.581+0200    DEBUG   database        [unexpected EOF]
2024-04-08T14:41:53.878+0200    DEBUG   database        [unexpected EOF]
...
2024-04-08T14:46:12.751+0200    DEBUG   database        [closing bad idle connection:  EOF]
2024-04-08T14:46:12.751+0200    DEBUG   database        [closing bad idle connection:  EOF]
2024-04-08T14:46:12.751+0200    DEBUG   database        [closing bad idle connection:  EOF]
2024-04-08T14:46:12.751+0200    DEBUG   database        [closing bad idle connection:  EOF]
2024-04-08T14:46:12.753+0200    DEBUG   database        [closing bad idle connection:  EOF]

@yhabteab yhabteab added the bug Something isn't working label Apr 8, 2024
@yhabteab yhabteab added this to the 1.1.2 milestone Apr 8, 2024
@yhabteab yhabteab requested a review from oxzi April 8, 2024 12:48
@cla-bot cla-bot bot added the cla/signed label Apr 8, 2024
@yhabteab yhabteab changed the title Register mysql default logger prior to 'mysql#NewConfig()' Register mysql default logger prior to mysql#NewConfig() Apr 8, 2024
oxzi
oxzi previously approved these changes Apr 8, 2024
@julianbrost
Copy link
Contributor

Do we even care about the default logger? Currently, all it does is to set the public Logger attribute on the Config struct:

https://github.com/go-sql-driver/mysql/blob/4395c45fd098a81c5251667cda111f94c693ab14/errors.go#L53-L61
https://github.com/go-sql-driver/mysql/blob/4395c45fd098a81c5251667cda111f94c693ab14/dsn.go#L89
https://github.com/go-sql-driver/mysql/blob/4395c45fd098a81c5251667cda111f94c693ab14/dsn.go#L202-L204

Unfortunately, the documentation for SetLogger() doesn't explicitly state that there will never be logging outside of a connection:

SetLogger is used to set the default logger for critical errors. The initial logger is os.Stderr.

However, I think it's not totally unreasonable to assume that it stays this way (default logger kind of suggests that it just serves as the default for Config and even if it would change at some point in the future, it would be a bit annoying, but that's it).

I have the feeling that the default logger was only set as before #711, when the database was opened from a DSN, there was no other way to set a logger. So maybe we just want to change it and simply set config.Logger instead?

@@ -42,6 +42,7 @@ func (d *Database) Open(logger *logging.Logger) (*icingadb.DB, error) {

config.User = d.User
config.Passwd = d.Password
config.Logger = icingadb.MysqlFuncLogger(logger.Debug)
Copy link
Member

Choose a reason for hiding this comment

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

I like the documentation 🥲

Logger               Logger            // Logger

@julianbrost julianbrost merged commit d91dc1e into main Apr 9, 2024
31 checks passed
@julianbrost julianbrost deleted the set-mysql-cfg-logger branch April 9, 2024 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cla/signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants