Skip to content

fix panic when logger or dialer is not set in canal config #743

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

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions canal/canal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"net"
"os"
"regexp"
"strconv"
Expand All @@ -19,6 +20,7 @@ import (
"github.com/go-mysql-org/go-mysql/schema"
"github.com/pingcap/errors"
"github.com/pingcap/parser"
"github.com/siddontang/go-log/log"
)

// Canal can sync your MySQL data into everywhere, like Elasticsearch, Redis, etc...
Expand Down Expand Up @@ -60,6 +62,14 @@ var ErrExcludedTable = errors.New("excluded table meta")

func NewCanal(cfg *Config) (*Canal, error) {
c := new(Canal)
if cfg.Logger == nil {
streamHandler, _ := log.NewStreamHandler(os.Stdout)
cfg.Logger = log.NewDefault(streamHandler)
}
if cfg.Dialer == nil {
dialer := &net.Dialer{}
cfg.Dialer = dialer.DialContext
}
c.cfg = cfg

c.ctx, c.cancel = context.WithCancel(context.Background())
Expand Down