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

Allow logger override #699

Merged
merged 2 commits into from Jun 11, 2022

Conversation

cameron-p-m
Copy link
Contributor

@cameron-p-m cameron-p-m commented Jun 9, 2022

Problem

Ideally libraries don't have a logger at all. But this is a smaller change by allowing a user to set the Logger. This will allow the previous behaviour if needed.

Closes: #698 and maybe others

Feedback?

Should errors ever log or just return?

@cameron-p-m
Copy link
Contributor Author

@lance6716 tagging you, let me know if there is somebody better to tag

@@ -107,7 +105,6 @@ func (c *Canal) runSyncBinlog() error {
if e != ErrExcludedTable &&
e != schema.ErrTableNotExist &&
e != schema.ErrMissingTableMeta {
log.Errorf("handle rows event at (%s, %d) error %v", pos.Name, curPos, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

why not replace this with a call to c.cfg.Logger.Errorf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can if you want!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we should log errors in the library, just return them

Copy link
Contributor

Choose a reason for hiding this comment

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

that seems like the consistent thing to do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure I will change

@lance6716
Copy link
Collaborator

thanks for your pr! I'm quite busy today, I will take a look tomorrow.

@cameron-p-m
Copy link
Contributor Author

@lance6716 Sounds good. If there is anything I need to do to bump the version, let me know. I would like to start using this without using a fork :)

Copy link
Collaborator

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

I'll remove "close #632" in PR description, because other place such as binlogsyncer.go still access the default logger.

canal/master.go Show resolved Hide resolved
canal/config.go Outdated Show resolved Hide resolved
@cameron-p-m
Copy link
Contributor Author

@lance6716 I made the same change in binlog syncer too now

Copy link
Collaborator

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

found that there's still some reference to global logger, like go-mysqldump, https://github.com/cameron-p-m/go-mysql/blob/fix/allow-setting-logger/mysql/mariadb_gtid.go#L96 . But it's OK to left them for a future PR.

unit tests failed, rest lgtm

@skoef do you have any comment?

@skoef
Copy link
Contributor

skoef commented Jun 11, 2022

I'm fine with this!

Perhaps sometimes we can refactor using siddontang/go-log and have it replaced with something more generic/mainstream as it seems that siddontang/go-log is no longer maintained. But that's beyond the scope of this PR!

@cameron-p-m
Copy link
Contributor Author

@lance6716 updated and fixed tests

@lance6716 lance6716 merged commit 62e8407 into go-mysql-org:master Jun 11, 2022
@naughtyGitCat
Copy link

@lance6716 when we can use this feature, v1.6? is there any way to use latest master code

@lance6716
Copy link
Collaborator

@atercattus Do you have a release plan?

@naughtyGitCat Currently you can specify the master branch or commit hash in go.mod https://go.dev/ref/mod#vcs-branch

@atercattus
Copy link
Member

@lance6716, I'll do it soon.

@atercattus
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add options or expose method to set logger output media
5 participants