Skip to content

Commit

Permalink
log: replace pingcap global logger when start dumpling binary (pingca…
Browse files Browse the repository at this point in the history
  • Loading branch information
lichunzhu authored Apr 14, 2021
1 parent e1cfe4c commit 0a1f0d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
12 changes: 9 additions & 3 deletions v4/export/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/pingcap/br/pkg/summary"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
pclog "github.com/pingcap/log"
pd "github.com/tikv/pd/client"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -766,19 +767,24 @@ func runSteps(d *Dumper, steps ...func(*Dumper) error) error {

func initLogger(d *Dumper) error {
conf := d.conf
var logger log.Logger
var (
logger log.Logger
err error
props *pclog.ZapProperties
)
// conf.Logger != nil means dumpling is used as a library
if conf.Logger != nil {
logger = log.NewAppLogger(conf.Logger)
} else {
var err error
logger, err = log.InitAppLogger(&log.Config{
logger, props, err = log.InitAppLogger(&log.Config{
Level: conf.LogLevel,
File: conf.LogFile,
Format: conf.LogFormat,
})
if err != nil {
return errors.Trace(err)
}
pclog.ReplaceGlobals(logger.Logger, props)
cli.LogLongVersion(logger)
}
d.tctx = d.tctx.WithLogger(logger)
Expand Down
2 changes: 1 addition & 1 deletion v4/export/writer_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var appLogger log.Logger

func TestT(t *testing.T) {
initColTypeRowReceiverMap()
logger, err := log.InitAppLogger(&log.Config{
logger, _, err := log.InitAppLogger(&log.Config{
Level: "info",
File: "",
Format: "text",
Expand Down
8 changes: 4 additions & 4 deletions v4/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type Config struct {
}

// InitAppLogger inits the wrapped logger from config.
func InitAppLogger(cfg *Config) (Logger, error) {
logger, _, err := pclog.InitLogger(&pclog.Config{
func InitAppLogger(cfg *Config) (Logger, *pclog.ZapProperties, error) {
logger, props, err := pclog.InitLogger(&pclog.Config{
Level: cfg.Level,
File: pclog.FileLogConfig{
Filename: cfg.File,
Expand All @@ -50,9 +50,9 @@ func InitAppLogger(cfg *Config) (Logger, error) {
Format: cfg.Format,
})
if err != nil {
return appLogger, errors.Trace(err)
return appLogger, props, errors.Trace(err)
}
return Logger{logger.WithOptions(zap.AddStacktrace(zap.DPanicLevel))}, nil
return Logger{logger.WithOptions(zap.AddStacktrace(zap.DPanicLevel))}, props, nil
}

// NewAppLogger returns the wrapped logger from config.
Expand Down

0 comments on commit 0a1f0d3

Please sign in to comment.