Skip to content

how to remove log output #848

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

Closed
deadspacewii opened this issue Jan 31, 2024 · 4 comments · Fixed by #953
Closed

how to remove log output #848

deadspacewii opened this issue Jan 31, 2024 · 4 comments · Fixed by #953

Comments

@deadspacewii
Copy link
Contributor

how can I remove log output from canal,i will use my own log instead of canal's default log

@cameron-p-m
Copy link
Contributor

Something like this.

	cfg := canal.NewDefaultConfig()
	// disable embedded canal logs
	cfg.Logger = log.NewDefault(&log.NullHandler{})

@deadspacewii
Copy link
Contributor Author

Something like this.

	cfg := canal.NewDefaultConfig()
	// disable embedded canal logs
	cfg.Logger = log.NewDefault(&log.NullHandler{})

Thanks

@dveeden
Copy link
Collaborator

dveeden commented Nov 22, 2024

Either with this:

import "github.com/siddontang/go-log/log"
...
        streamHandler, _ := log.NewStreamHandler(io.Discard)
        cfg.Logger = log.NewDefault(streamHandler)

Or this:

import "github.com/siddontang/go-log/log"
...
        nullHandler, _ := log.NewNullHandler()
        cfg.Logger = log.NewDefault(nullHandler)

I think we need to update the docs for this.

Also for me there was still some logging:

$ ./bin/go-canal
[2024/11/22 10:35:42] [info] dumper.go:309 exec mysqldump with [--host=127.0.0.1 --port=3306 --user=root --password=****** --source-data --single-transaction --skip-lock-tables --compact --skip-opt --quick --no-create-info --skip-extended-insert --skip-tz-utc --hex-blob --default-character-set=utf8 --column-statistics=0 --databases test]
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events. 
insert test.t1 [[1]]
insert test.t1 [[2]]
insert test.t1 [[1]]
  • One line is from mysqldump where we probably let it write to stderr.
  • One line is from dumper.go:309 and I'm not sure why that's showing

@dveeden
Copy link
Collaborator

dveeden commented Nov 22, 2024

Note that the import that my tools add is wrong and results in:

$ make build
go build -o bin/go-mysqlbinlog cmd/go-mysqlbinlog/main.go
go build -o bin/go-mysqldump cmd/go-mysqldump/main.go
go build -o bin/go-canal cmd/go-canal/main.go
# command-line-arguments
cmd/go-canal/main.go:54:15: cannot use log.NewDefault(nullHandler) (value of type *"github.com/siddontang/go/log".Logger) as loggers.Advanced value in assignment: *"github.com/siddontang/go/log".Logger does not implement loggers.Advanced (missing method Debugln)
cmd/go-canal/main.go:54:30: cannot use nullHandler (variable of type *"github.com/siddontang/go/log".NullHandler) as "github.com/siddontang/go/log".Handler value in argument to log.NewDefault: *"github.com/siddontang/go/log".NullHandler does not implement "github.com/siddontang/go/log".Handler (wrong type for method Close)
		have Close()
		want Close() error
make: *** [Makefile:10: build] Error 1

The tools add github.com/siddontang/go/log instead of github.com/siddontang/go-log/log. After correcting this by hand everything works fine.

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

Successfully merging a pull request may close this issue.

3 participants