From 611e959c012bfc4202f951f00e305922bc5feeb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Sat, 23 Nov 2024 15:34:30 +0100 Subject: [PATCH 1/3] canal,dump: Improve logging (#953) --- README.md | 24 ++++++++++++++++++++++++ canal/canal.go | 3 +++ dump/dumper.go | 8 +++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba1813a0b..a768a3747 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ This repo uses [Changelog](CHANGELOG.md). * [Client](#client) * [Fake server](#server) * [database/sql like driver](#driver) +* [Logging](#logging) ## Replication @@ -492,6 +493,29 @@ func main() { We pass all tests in https://github.com/bradfitz/go-sql-test using go-mysql driver. :-) +## Logging + +Logging by default is send to stdout. + +To disable logging completely: +```go +import "github.com/siddontang/go-log/log" +... + nullHandler, _ := log.NewNullHandler() + cfg.Logger = log.NewDefault(nullHandler) +``` + +To write logging to any [`io.Writer`](https://pkg.go.dev/io#Writer): +```go +import "github.com/siddontang/go-log/log" +... + w := ... + streamHandler, _ := log.NewStreamHandler(w) + cfg.Logger = log.NewDefault(streamHandler) +``` + +Or you can implement your own [`log.Handler`](https://pkg.go.dev/github.com/siddontang/go-log/log#Handler). + ## Donate If you like the project and want to buy me a cola, you can through: diff --git a/canal/canal.go b/canal/canal.go index 64a1c343e..005c67050 100644 --- a/canal/canal.go +++ b/canal/canal.go @@ -153,6 +153,9 @@ func (c *Canal) prepareDumper() error { return nil } + // use the same logger for the dumper + c.dumper.Logger = c.cfg.Logger + dbs := c.cfg.Dump.Databases tables := c.cfg.Dump.Tables tableDB := c.cfg.Dump.TableDB diff --git a/dump/dumper.go b/dump/dumper.go index b2b7e4377..91179a0c1 100644 --- a/dump/dumper.go +++ b/dump/dumper.go @@ -13,6 +13,7 @@ import ( . "github.com/go-mysql-org/go-mysql/mysql" "github.com/pingcap/errors" "github.com/siddontang/go-log/log" + "github.com/siddontang/go-log/loggers" ) // Unlick mysqldump, Dumper is designed for parsing and syning data easily. @@ -49,6 +50,8 @@ type Dumper struct { mysqldumpVersion string sourceDataSupported bool + + Logger loggers.Advanced } func NewDumper(executionPath string, addr string, user string, password string) (*Dumper, error) { @@ -93,6 +96,9 @@ func NewDumper(executionPath string, addr string, user string, password string) d.ErrOut = os.Stderr + streamHandler, _ := log.NewStreamHandler(os.Stdout) + d.Logger = log.NewDefault(streamHandler) + return d, nil } @@ -306,7 +312,7 @@ func (d *Dumper) Dump(w io.Writer) error { } args[passwordArgIndex] = "--password=******" - log.Infof("exec mysqldump with %v", args) + d.Logger.Infof("exec mysqldump with %v", args) args[passwordArgIndex] = passwordArg cmd := exec.Command(d.ExecutionPath, args...) From 01269865a7cf0283b5b8c67bc938716fab8152c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Wed, 27 Nov 2024 13:42:32 +0100 Subject: [PATCH 2/3] CI: Update Go, MySQL and Ubuntu versions (#954) * CI: Update Go, MySQL and Ubuntu versions * Trigger Build --------- Co-authored-by: lance6716 --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6036731df..ef678faae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,8 +5,8 @@ jobs: test: strategy: matrix: - go: [ "1.22", "1.21" ] - os: [ ubuntu-22.04, ubuntu-20.04 ] + go: [ "1.23", "1.22" ] + os: [ ubuntu-24.04, ubuntu-22.04, ubuntu-20.04 ] name: Tests Go ${{ matrix.go }} on ${{ matrix.os }} # This name is used in main branch protection rules runs-on: ${{ matrix.os }} @@ -51,8 +51,8 @@ jobs: strategy: matrix: mysql_version: - - 8.0.37 - - 8.4.0 + - 8.0.40 + - 8.4.3 name: Tests with MySQL ${{ matrix.mysql_version }} runs-on: ubuntu-latest services: @@ -78,7 +78,7 @@ jobs: - name: Install Go uses: actions/setup-go@v5 with: - go-version: "1.22" + go-version: "1.23" - name: Run tests run: | # separate test to avoid RESET MASTER conflict @@ -113,7 +113,7 @@ jobs: - name: Install Go uses: actions/setup-go@v5 with: - go-version: "1.22" + go-version: "1.23" - name: Build on ${{ matrix.os }}/${{ matrix.arch }} run: GOARCH=${{ matrix.arch }} GOOS=${{ matrix.os }} go build ./... From 506416d3f6cd2414b2cdd0d5eab5eea08190e799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Wed, 4 Dec 2024 03:41:20 +0100 Subject: [PATCH 3/3] README: fix example for database/sql (#955) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a768a3747..4f1a5f650 100644 --- a/README.md +++ b/README.md @@ -342,7 +342,7 @@ import ( func main() { // dsn format: "user:password@addr?dbname" dsn := "root@127.0.0.1:3306?test" - db, _ := sql.Open(dsn) + db, _ := sql.Open("mysql", dsn) db.Close() } ```