Skip to content
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

*: clean up the logging component #23534

Merged
merged 16 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (b *nullableBool) UnmarshalJSON(data []byte) error {
type Log struct {
// Log level.
Level string `toml:"level" json:"level"`
// Log format. one of json, text, or console.
// Log format, one of json or text.
Format string `toml:"format" json:"format"`
// Disable automatic timestamps in output. Deprecated: use EnableTimestamp instead.
DisableTimestamp nullableBool `toml:"disable-timestamp" json:"disable-timestamp"`
Expand Down
2 changes: 1 addition & 1 deletion config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ enable-enum-length-limit = true
# Log level: debug, info, warn, error, fatal.
level = "info"

# Log format, one of json, text, console.
# Log format, one of json or text.
format = "text"

# Enable automatic timestamps in log output, if not set, it will be defaulted to true.
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ require (
github.com/prometheus/common v0.9.1
github.com/rivo/uniseg v0.2.0 // indirect
github.com/shirou/gopsutil v3.21.2+incompatible
github.com/sirupsen/logrus v1.6.0
github.com/sirupsen/logrus v1.6.0 // indirect
SabaPing marked this conversation as resolved.
Show resolved Hide resolved
github.com/soheilhy/cmux v0.1.4
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/tikv/pd v1.1.0-beta.0.20210323121136-78679e5e209d
Expand All @@ -83,7 +83,6 @@ require (
golang.org/x/tools v0.1.0
google.golang.org/grpc v1.27.1
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
honnef.co/go/tools v0.1.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44 h1:tB9NOR21++IjLyVx3/PCPhWMwqGNCMQEH96A6dMZ/gc=
github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shirou/gopsutil v2.19.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v3.21.2+incompatible h1:U+YvJfjCh6MslYlIAXvPtzhW3YZEtc9uncueUNpD/0A=
Expand Down
25 changes: 9 additions & 16 deletions server/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/log"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/config"
Expand Down Expand Up @@ -62,7 +63,6 @@ import (
"github.com/pingcap/tidb/util/gcutil"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/pdapi"
log "github.com/sirupsen/logrus"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -701,13 +701,6 @@ func (h settingsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}

l, err1 := log.ParseLevel(levelStr)
if err1 != nil {
writeError(w, err1)
return
}
log.SetLevel(l)

config.GetGlobalConfig().Log.Level = levelStr
}
if generalLog := req.Form.Get("tidb_general_log"); generalLog != "" {
Expand Down Expand Up @@ -1180,7 +1173,7 @@ func (h ddlResignOwnerHandler) ServeHTTP(w http.ResponseWriter, req *http.Reques

err := h.resignDDLOwner()
if err != nil {
log.Error(err)
log.Error("failed to resign DDL owner", zap.Error(err))
writeError(w, err)
return
}
Expand Down Expand Up @@ -1224,7 +1217,7 @@ func (h tableHandler) addScatterSchedule(startKey, endKey []byte, name string) e
return err
}
if err := resp.Body.Close(); err != nil {
log.Error(err)
log.Error("failed to close response body", zap.Error(err))
}
return nil
}
Expand All @@ -1244,7 +1237,7 @@ func (h tableHandler) deleteScatterSchedule(name string) error {
return err
}
if err := resp.Body.Close(); err != nil {
log.Error(err)
log.Error("failed to close response body", zap.Error(err))
}
return nil
}
Expand Down Expand Up @@ -1740,14 +1733,14 @@ func (h serverInfoHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
do, err := session.GetDomain(h.Store.(kv.Storage))
if err != nil {
writeError(w, errors.New("create session error"))
log.Error(err)
log.Error("failed to get session domain", zap.Error(err))
return
}
info := serverInfo{}
info.ServerInfo, err = infosync.GetServerInfo()
if err != nil {
writeError(w, err)
log.Error(err)
log.Error("failed to get server info", zap.Error(err))
return
}
info.IsOwner = do.DDL().OwnerManager().IsOwner()
Expand All @@ -1770,22 +1763,22 @@ func (h allServerInfoHandler) ServeHTTP(w http.ResponseWriter, req *http.Request
do, err := session.GetDomain(h.Store.(kv.Storage))
if err != nil {
writeError(w, errors.New("create session error"))
log.Error(err)
log.Error("failed to get session domain", zap.Error(err))
return
}
ctx := context.Background()
allServersInfo, err := infosync.GetAllServerInfo(ctx)
if err != nil {
writeError(w, errors.New("ddl server information not found"))
log.Error(err)
log.Error("failed to get all server info", zap.Error(err))
return
}
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
ownerID, err := do.DDL().OwnerManager().GetOwnerID(ctx)
cancel()
if err != nil {
writeError(w, errors.New("ddl server information not found"))
log.Error(err)
log.Error("failed to get owner id", zap.Error(err))
return
}
allVersionsMap := map[infosync.ServerVersionInfo]struct{}{}
Expand Down
11 changes: 4 additions & 7 deletions server/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
zaplog "github.com/pingcap/log"
"github.com/pingcap/log"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/config"
Expand All @@ -58,7 +58,6 @@ import (
"github.com/pingcap/tidb/util/codec"
"github.com/pingcap/tidb/util/rowcodec"
"github.com/pingcap/tidb/util/versioninfo"
log "github.com/sirupsen/logrus"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -1149,8 +1148,7 @@ func (ts *HTTPHandlerTestSuite) TestPostSettings(c *C) {
resp, err := ts.formStatus("/settings", form)
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
c.Assert(log.GetLevel(), Equals, log.ErrorLevel)
c.Assert(zaplog.GetLevel(), Equals, zap.ErrorLevel)
c.Assert(log.GetLevel(), Equals, zap.ErrorLevel)
c.Assert(config.GetGlobalConfig().Log.Level, Equals, "error")
c.Assert(variable.ProcessGeneralLog.Load(), IsTrue)
val, err := variable.GetGlobalSystemVar(se.GetSessionVars(), variable.TiDBEnableAsyncCommit)
Expand All @@ -1169,8 +1167,7 @@ func (ts *HTTPHandlerTestSuite) TestPostSettings(c *C) {
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
c.Assert(variable.ProcessGeneralLog.Load(), IsFalse)
c.Assert(log.GetLevel(), Equals, log.FatalLevel)
c.Assert(zaplog.GetLevel(), Equals, zap.FatalLevel)
c.Assert(log.GetLevel(), Equals, zap.FatalLevel)
c.Assert(config.GetGlobalConfig().Log.Level, Equals, "fatal")
val, err = variable.GetGlobalSystemVar(se.GetSessionVars(), variable.TiDBEnableAsyncCommit)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -1238,7 +1235,7 @@ func (ts *HTTPHandlerTestSuite) TestPprof(c *C) {
}
time.Sleep(time.Millisecond * 10)
}
zaplog.Fatal("failed to get profile for %d retries in every 10 ms", zap.Int("retryTime", retryTime))
log.Fatal("failed to get profile for %d retries in every 10 ms", zap.Int("retryTime", retryTime))
}

func (ts *HTTPHandlerTestSuite) TestServerInfo(c *C) {
Expand Down
10 changes: 0 additions & 10 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"os"
"runtime"
"strconv"
Expand Down Expand Up @@ -68,7 +67,6 @@ import (
pd "github.com/tikv/pd/client"
"go.uber.org/automaxprocs/maxprocs"
"go.uber.org/zap"
"google.golang.org/grpc/grpclog"
)

// Flag Names
Expand Down Expand Up @@ -575,14 +573,6 @@ func setupLog() {
err := logutil.InitZapLogger(cfg.Log.ToLogConfig())
terror.MustNil(err)

err = logutil.InitLogger(cfg.Log.ToLogConfig())
terror.MustNil(err)

if len(os.Getenv("GRPC_DEBUG")) > 0 {
grpclog.SetLoggerV2(grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 999))
} else {
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, os.Stderr))
}
// trigger internal http(s) client init.
util.InternalHTTPClient()
}
Expand Down
Loading