Skip to content

Commit

Permalink
utils: make TiKV less verbose (#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD authored and davies committed Aug 16, 2021
1 parent 1636871 commit 5c21289
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ func setLoggerLevel(c *cli.Context) {
utils.SetLogLevel(logrus.DebugLevel)
} else if c.Bool("quiet") {
utils.SetLogLevel(logrus.WarnLevel)
} else {
utils.SetLogLevel(logrus.InfoLevel)
}
setupAgent(c)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ require (
github.com/minio/minio-go v6.0.14+incompatible
github.com/ncw/swift v1.0.53
github.com/pengsrc/go-shared v0.2.0 // indirect
github.com/pingcap/log v0.0.0-20210317133921-96f4fcab92a4
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.10.0
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 // indirect
Expand Down
7 changes: 4 additions & 3 deletions pkg/meta/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"

"github.com/juicedata/juicefs/pkg/utils"

"github.com/sirupsen/logrus"
)

const (
Expand All @@ -32,11 +34,10 @@ const (
tkvAddr = "tikv://127.0.0.1:2379/juicefs"
)

/*
func init() {
utils.SetOutFile("bench-test.log")
utils.SetLogLevel(logrus.InfoLevel)
// utils.SetOutFile("bench-test.log")
}
*/

func encodeSlices(size int) []string {
w := utils.NewBuffer(24)
Expand Down
19 changes: 19 additions & 0 deletions pkg/utils/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"
"sync"

plog "github.com/pingcap/log"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -108,6 +109,24 @@ func SetLogLevel(lvl logrus.Level) {
for _, logger := range loggers {
logger.Level = lvl
}
var plvl string // TiKV (PingCap) uses uber-zap logging, make it less verbose
switch lvl {
case logrus.TraceLevel:
plvl = "debug"
case logrus.DebugLevel:
plvl = "info"
case logrus.InfoLevel:
fallthrough
case logrus.WarnLevel:
plvl = "warn"
case logrus.ErrorLevel:
plvl = "error"
default:
plvl = "dpanic"
}
conf := &plog.Config{Level: plvl}
l, p, _ := plog.InitLogger(conf)
plog.ReplaceGlobals(l, p)
}

func SetOutFile(name string) {
Expand Down

0 comments on commit 5c21289

Please sign in to comment.