Skip to content

Commit b93dfec

Browse files
committed
Merge branch 'master' of github.com:go-mysql-org/go-mysql into update_readme
Signed-off-by: lance6716 <[email protected]>
2 parents 6e48ab4 + 506416d commit b93dfec

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ jobs:
55
test:
66
strategy:
77
matrix:
8-
go: [ "1.22", "1.21" ]
9-
os: [ ubuntu-22.04, ubuntu-20.04 ]
8+
go: [ "1.23", "1.22" ]
9+
os: [ ubuntu-24.04, ubuntu-22.04, ubuntu-20.04 ]
1010
name: Tests Go ${{ matrix.go }} on ${{ matrix.os }} # This name is used in main branch protection rules
1111
runs-on: ${{ matrix.os }}
1212

@@ -51,8 +51,8 @@ jobs:
5151
strategy:
5252
matrix:
5353
mysql_version:
54-
- 8.0.37
55-
- 8.4.0
54+
- 8.0.40
55+
- 8.4.3
5656
name: Tests with MySQL ${{ matrix.mysql_version }}
5757
runs-on: ubuntu-latest
5858
services:
@@ -78,7 +78,7 @@ jobs:
7878
- name: Install Go
7979
uses: actions/setup-go@v5
8080
with:
81-
go-version: "1.22"
81+
go-version: "1.23"
8282
- name: Run tests
8383
run: |
8484
# separate test to avoid RESET MASTER conflict
@@ -113,7 +113,7 @@ jobs:
113113
- name: Install Go
114114
uses: actions/setup-go@v5
115115
with:
116-
go-version: "1.22"
116+
go-version: "1.23"
117117

118118
- name: Build on ${{ matrix.os }}/${{ matrix.arch }}
119119
run: GOARCH=${{ matrix.arch }} GOOS=${{ matrix.os }} go build ./...

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This repo uses [Changelog](CHANGELOG.md).
1717
* [Client](#client) - Simple MySQL client.
1818
* [Fake server](#server) - server side of the MySQL protocol, as library.
1919
* [database/sql like driver](#driver) - An alternative `database/sql` driver for MySQL.
20+
* [Logging](#logging) - Custom logging options.
2021
* [Migration](#how-to-migrate-to-this-repo) - Information for how to migrate if you used the old location of this project.
2122

2223
## Examples
@@ -346,7 +347,7 @@ import (
346347
func main() {
347348
// dsn format: "user:password@addr?dbname"
348349
dsn := "[email protected]:3306?test"
349-
db, _ := sql.Open(dsn)
350+
db, _ := sql.Open("mysql", dsn)
350351
db.Close()
351352
}
352353
```
@@ -497,6 +498,29 @@ func main() {
497498

498499
We pass all tests in https://github.com/bradfitz/go-sql-test using go-mysql driver. :-)
499500

501+
## Logging
502+
503+
Logging by default is send to stdout.
504+
505+
To disable logging completely:
506+
```go
507+
import "github.com/siddontang/go-log/log"
508+
...
509+
nullHandler, _ := log.NewNullHandler()
510+
cfg.Logger = log.NewDefault(nullHandler)
511+
```
512+
513+
To write logging to any [`io.Writer`](https://pkg.go.dev/io#Writer):
514+
```go
515+
import "github.com/siddontang/go-log/log"
516+
...
517+
w := ...
518+
streamHandler, _ := log.NewStreamHandler(w)
519+
cfg.Logger = log.NewDefault(streamHandler)
520+
```
521+
522+
Or you can implement your own [`log.Handler`](https://pkg.go.dev/github.com/siddontang/go-log/log#Handler).
523+
500524
## How to migrate to this repo
501525
To change the used package in your repo it's enough to add this `replace` directive to your `go.mod`:
502526
```

canal/canal.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ func (c *Canal) prepareDumper() error {
153153
return nil
154154
}
155155

156+
// use the same logger for the dumper
157+
c.dumper.Logger = c.cfg.Logger
158+
156159
dbs := c.cfg.Dump.Databases
157160
tables := c.cfg.Dump.Tables
158161
tableDB := c.cfg.Dump.TableDB

dump/dumper.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
. "github.com/go-mysql-org/go-mysql/mysql"
1414
"github.com/pingcap/errors"
1515
"github.com/siddontang/go-log/log"
16+
"github.com/siddontang/go-log/loggers"
1617
)
1718

1819
// Unlick mysqldump, Dumper is designed for parsing and syning data easily.
@@ -49,6 +50,8 @@ type Dumper struct {
4950

5051
mysqldumpVersion string
5152
sourceDataSupported bool
53+
54+
Logger loggers.Advanced
5255
}
5356

5457
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)
9396

9497
d.ErrOut = os.Stderr
9598

99+
streamHandler, _ := log.NewStreamHandler(os.Stdout)
100+
d.Logger = log.NewDefault(streamHandler)
101+
96102
return d, nil
97103
}
98104

@@ -306,7 +312,7 @@ func (d *Dumper) Dump(w io.Writer) error {
306312
}
307313

308314
args[passwordArgIndex] = "--password=******"
309-
log.Infof("exec mysqldump with %v", args)
315+
d.Logger.Infof("exec mysqldump with %v", args)
310316
args[passwordArgIndex] = passwordArg
311317
cmd := exec.Command(d.ExecutionPath, args...)
312318

0 commit comments

Comments
 (0)