Skip to content

Commit

Permalink
*: use the unified log format for the remaining packages (pingcap#9743)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored and xiekeyi98 committed Mar 22, 2019
1 parent facadf7 commit b78490e
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 100 deletions.
15 changes: 8 additions & 7 deletions cmd/benchdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import (
"strings"
"time"

"github.com/pingcap/log"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/store"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/util/logutil"
log "github.com/sirupsen/logrus"
"go.uber.org/zap"
)

var (
Expand Down Expand Up @@ -55,7 +56,7 @@ var (
func main() {
flag.Parse()
flag.PrintDefaults()
err := logutil.InitLogger(logutil.NewLogConfig(*logLevel, logutil.DefaultLogFormat, "", logutil.EmptyFileLogConfig, false))
err := logutil.InitZapLogger(logutil.NewLogConfig(*logLevel, logutil.DefaultLogFormat, "", logutil.EmptyFileLogConfig, false))
terror.MustNil(err)
err = store.Register("tikv", tikv.Driver{})
terror.MustNil(err)
Expand Down Expand Up @@ -111,7 +112,7 @@ func newBenchDB() *benchDB {
func (ut *benchDB) mustExec(sql string) {
rss, err := ut.session.Execute(context.Background(), sql)
if err != nil {
log.Fatal(err)
log.Fatal(err.Error())
}
if len(rss) > 0 {
ctx := context.Background()
Expand All @@ -120,7 +121,7 @@ func (ut *benchDB) mustExec(sql string) {
for {
err := rs.Next(ctx, req)
if err != nil {
log.Fatal(err)
log.Fatal(err.Error())
}
if req.NumRows() == 0 {
break
Expand All @@ -140,21 +141,21 @@ func (ut *benchDB) mustParseWork(work string) (name string, spec string) {
func (ut *benchDB) mustParseInt(s string) int {
i, err := strconv.Atoi(s)
if err != nil {
log.Fatal(err)
log.Fatal(err.Error())
}
return i
}

func (ut *benchDB) mustParseRange(s string) (start, end int) {
strs := strings.Split(s, "_")
if len(strs) != 2 {
log.Fatal("invalid range " + s)
log.Fatal("parse range failed", zap.String("invalid range", s))
}
startStr, endStr := strs[0], strs[1]
start = ut.mustParseInt(startStr)
end = ut.mustParseInt(endStr)
if start < 0 || end < start {
log.Fatal("invalid range " + s)
log.Fatal("parse range failed", zap.String("invalid range", s))
}
return
}
Expand Down
24 changes: 12 additions & 12 deletions cmd/benchfilesort/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/codec"
"github.com/pingcap/tidb/util/filesort"
"github.com/pingcap/tidb/util/logutil"
log "github.com/sirupsen/logrus"
)

type comparableRow struct {
Expand Down Expand Up @@ -264,19 +264,19 @@ func driveGenCmd() {
terror.MustNil(err)
// Sanity checks
if keySize <= 0 {
log.Fatal(errors.New("key size must be positive"))
log.Fatal("key size must be positive")
}
if valSize <= 0 {
log.Fatal(errors.New("value size must be positive"))
log.Fatal("value size must be positive")
}
if scale <= 0 {
log.Fatal(errors.New("scale must be positive"))
log.Fatal("scale must be positive")
}
if _, err = os.Stat(tmpDir); err != nil {
if os.IsNotExist(err) {
log.Fatal(errors.New("tmpDir does not exist"))
log.Fatal("tmpDir does not exist")
}
log.Fatal(err)
log.Fatal(err.Error())
}

cLog("Generating...")
Expand All @@ -294,20 +294,20 @@ func driveRunCmd() {
terror.MustNil(err)
// Sanity checks
if bufSize <= 0 {
log.Fatal(errors.New("buffer size must be positive"))
log.Fatal("buffer size must be positive")
}
if nWorkers <= 0 {
log.Fatal(errors.New("the number of workers must be positive"))
log.Fatal("the number of workers must be positive")
}
if inputRatio < 0 || inputRatio > 100 {
log.Fatal(errors.New("input ratio must between 0 and 100 (inclusive)"))
log.Fatal("input ratio must between 0 and 100 (inclusive)")
}
if outputRatio < 0 || outputRatio > 100 {
log.Fatal(errors.New("output ratio must between 0 and 100 (inclusive)"))
log.Fatal("output ratio must between 0 and 100 (inclusive)")
}
if _, err = os.Stat(tmpDir); err != nil {
if os.IsNotExist(err) {
log.Fatal(errors.New("tmpDir does not exist"))
log.Fatal("tmpDir does not exist")
}
terror.MustNil(err)
}
Expand Down Expand Up @@ -382,7 +382,7 @@ func driveRunCmd() {
}

func init() {
err := logutil.InitLogger(logutil.NewLogConfig(logLevel, logutil.DefaultLogFormat, "", logutil.EmptyFileLogConfig, false))
err := logutil.InitZapLogger(logutil.NewLogConfig(logLevel, logutil.DefaultLogFormat, "", logutil.EmptyFileLogConfig, false))
terror.MustNil(err)
cwd, err1 := os.Getwd()
terror.MustNil(err1)
Expand Down
7 changes: 4 additions & 3 deletions cmd/benchkv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"flag"
"fmt"
"go.uber.org/zap"
"io/ioutil"
"net/http"
_ "net/http/pprof"
Expand All @@ -25,11 +26,11 @@ import (

_ "github.com/go-sql-driver/mysql"
"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/store/tikv"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)

var (
Expand Down Expand Up @@ -100,7 +101,7 @@ func batchRW(value []byte) {
k := base*i + j
txn, err := store.Begin()
if err != nil {
log.Fatal(err)
log.Fatal(err.Error())
}
key := fmt.Sprintf("key_%d", k)
err = txn.Set([]byte(key), value)
Expand All @@ -120,7 +121,7 @@ func batchRW(value []byte) {

func main() {
flag.Parse()
log.SetLevel(log.ErrorLevel)
log.SetLevel(zap.ErrorLevel)
Init()

value := make([]byte, *valueSize)
Expand Down
9 changes: 5 additions & 4 deletions cmd/benchraw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/store/tikv"
log "github.com/sirupsen/logrus"
"go.uber.org/zap"
)

var (
Expand All @@ -47,7 +48,7 @@ func batchRawPut(value []byte) {
ClusterSSLKey: *sslKey,
})
if err != nil {
log.Fatal(err)
log.Fatal(err.Error())
}

wg := sync.WaitGroup{}
Expand All @@ -62,7 +63,7 @@ func batchRawPut(value []byte) {
key := fmt.Sprintf("key_%d", k)
err = cli.Put([]byte(key), value)
if err != nil {
log.Fatal(errors.ErrorStack(err))
log.Fatal("put failed", zap.Error(err))
}
}
}(i)
Expand All @@ -72,7 +73,7 @@ func batchRawPut(value []byte) {

func main() {
flag.Parse()
log.SetLevel(log.WarnLevel)
log.SetLevel(zap.WarnLevel)
go func() {
err := http.ListenAndServe(":9191", nil)
terror.Log(errors.Trace(err))
Expand Down
Loading

0 comments on commit b78490e

Please sign in to comment.