Skip to content

Commit

Permalink
*: use pingcap/log (zap) for logging (pingcap#162)
Browse files Browse the repository at this point in the history
* *: use pingcap/log (zap) for logging

Some redundant logs (e.g. logging about the same thing inside and outside
a function) are removed.

The {QueryRow,Transact,Exec}WithRetry functions are revamped to include
the logger.

* common,config: addressed comments

* *: addressed comments

* restore,verification: addressed comments
  • Loading branch information
kennytm authored Apr 19, 2019
1 parent ea3b27e commit a515465
Show file tree
Hide file tree
Showing 24 changed files with 1,611 additions and 1,517 deletions.
4 changes: 2 additions & 2 deletions cmd/tidb-lightning-ctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ func run() error {
}

if *logLevel != "" {
cfg.App.LogConfig.Level = *logLevel
cfg.App.Config.Level = *logLevel
}
if *logFilePath != "" {
cfg.App.LogConfig.File = *logFilePath
cfg.App.Config.File = *logFilePath
}
if *tidbHost != "" {
cfg.TiDB.Host = *tidbHost
Expand Down
13 changes: 8 additions & 5 deletions cmd/tidb-lightning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ package main

import (
"flag"
"fmt"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"

"github.com/pingcap/errors"
"github.com/pingcap/tidb-lightning/lightning"
"github.com/pingcap/tidb-lightning/lightning/common"
"github.com/pingcap/tidb-lightning/lightning/config"
"github.com/pingcap/tidb-lightning/lightning/log"
plan "github.com/pingcap/tidb/planner/core"
"go.uber.org/zap"
)

func setGlobalVars() {
Expand All @@ -42,7 +44,8 @@ func main() {
case flag.ErrHelp:
os.Exit(0)
default:
common.AppLogger.Fatalf("parse cmd flags error: %s", err)
fmt.Println("Failed to parse command flags: ", err)
os.Exit(1)
}

app := lightning.New(cfg)
Expand All @@ -56,15 +59,15 @@ func main() {

go func() {
sig := <-sc
common.AppLogger.Infof("Got signal %v to exit.", sig)
log.L().Info("got signal to exit", zap.Stringer("signal", sig))
app.Stop()
}()

err = app.Run()
if err != nil {
common.AppLogger.Error("tidb lightning encountered error:", errors.ErrorStack(err))
log.L().Error("tidb lightning encountered error", zap.Error(err))
os.Exit(1)
}

common.AppLogger.Info("tidb lightning exit.")
log.L().Info("tidb lightning exit")
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ require (
github.com/prometheus/client_golang v0.9.2
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.3.0
github.com/sirupsen/logrus v1.3.0 // indirect
github.com/unrolled/render v0.0.0-20190117215946-449f39850074 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
go.uber.org/zap v1.9.1
golang.org/x/text v0.3.0
google.golang.org/appengine v1.1.1-0.20180731164958-4216e58b9158 // indirect
google.golang.org/grpc v1.18.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)
53 changes: 53 additions & 0 deletions go.sum

Large diffs are not rendered by default.

178 changes: 0 additions & 178 deletions lightning/common/log.go

This file was deleted.

5 changes: 1 addition & 4 deletions lightning/common/once_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ type OnceError struct {
// Set assigns an error to this instance, if `e != nil`.
//
// If this method is called multiple times, only the first call is effective.
func (oe *OnceError) Set(tag string, e error) {
func (oe *OnceError) Set(e error) {
if e != nil {
oe.lock.Lock()
if oe.err == nil {
oe.err = e
}
oe.lock.Unlock()
if ShouldLogError(e) {
AppLogger.Errorf("[%s] error %v", tag, e)
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions lightning/common/once_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ func (s *onceErrorSuite) TestOnceError(c *C) {

c.Assert(err.Get(), IsNil)

err.Set("tag", nil)
err.Set(nil)
c.Assert(err.Get(), IsNil)

e := errors.New("1")
err.Set("tag", e)
err.Set(e)
c.Assert(err.Get(), Equals, e)

e2 := errors.New("2")
err.Set("tag", e2)
err.Set(e2)
c.Assert(err.Get(), Equals, e) // e, not e2.

err.Set("tag", nil)
err.Set(nil)
c.Assert(err.Get(), Equals, e)

ch := make(chan struct{})
go func() {
err.Set("tag", nil)
err.Set(nil)
ch <- struct{}{}
}()
<-ch
Expand Down
Loading

0 comments on commit a515465

Please sign in to comment.