From 80c2cfa940835bc80defb7f8702b3ae47777e589 Mon Sep 17 00:00:00 2001 From: nolouch Date: Wed, 30 Jan 2019 13:37:47 +0800 Subject: [PATCH] tiny clean Signed-off-by: nolouch --- cmd/pd-server/main.go | 5 +++++ go.mod | 3 ++- go.sum | 3 +++ pkg/logutil/log_test.go | 8 ++++---- server/config.go | 5 ++--- server/server.go | 2 +- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index 5702ef8cad8a..dd0da173f69a 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -58,6 +58,11 @@ func main() { if err != nil { log.S().Fatalf("initialize logger error: %s\n", fmt.Sprintf("%+v", err)) } + // Flushing any buffered log entries + defer func() { + log.S().Sync() + log.L().Sync() + }() // The old logger err = logutil.InitLogger(&cfg.Log) diff --git a/go.mod b/go.mod index 74e662813fe0..017b374ec08c 100644 --- a/go.mod +++ b/go.mod @@ -29,13 +29,14 @@ require ( github.com/pingcap/errors v0.10.1 // indirect github.com/pingcap/gofail v0.0.0-20181217135706-6a951c1e42c3 github.com/pingcap/kvproto v0.0.0-20181123124450-d48563486f61 - github.com/pingcap/log v0.0.0-20190124162537-b03a2096ae88 + github.com/pingcap/log v0.0.0-20190129103703-6afc545b8868 github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v0.8.0 github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5 // indirect github.com/sirupsen/logrus v1.0.5 github.com/spf13/cobra v0.0.3 github.com/spf13/pflag v1.0.1 + github.com/stretchr/objx v0.1.1 // indirect github.com/syndtr/goleveldb v0.0.0-20180815032940-ae2bd5eed72d github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6 // indirect github.com/unrolled/render v0.0.0-20171102162132-65450fb6b2d3 diff --git a/go.sum b/go.sum index 4426a38899ae..4581fe577a70 100644 --- a/go.sum +++ b/go.sum @@ -101,6 +101,8 @@ github.com/pingcap/kvproto v0.0.0-20181123124450-d48563486f61 h1:Yms1MiO/ezhE9oz github.com/pingcap/kvproto v0.0.0-20181123124450-d48563486f61/go.mod h1:0gwbe1F2iBIjuQ9AH0DbQhL+Dpr5GofU8fgYyXk+ykk= github.com/pingcap/log v0.0.0-20190124162537-b03a2096ae88 h1:44Uu74xgFR8G+PE71sSuTkuzWyfdKYFAuwzzOJIahig= github.com/pingcap/log v0.0.0-20190124162537-b03a2096ae88/go.mod h1:xsfkWVaFVV5B8e1K9seWfyJWFrIhbtUTAD8NV1Pq3+w= +github.com/pingcap/log v0.0.0-20190129103703-6afc545b8868 h1:zkyIcjTiuRIOvhuPvbB1wsRFZH5aPqz/3o7p8uAdEzU= +github.com/pingcap/log v0.0.0-20190129103703-6afc545b8868/go.mod h1:xsfkWVaFVV5B8e1K9seWfyJWFrIhbtUTAD8NV1Pq3+w= github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= @@ -125,6 +127,7 @@ github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3 github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= diff --git a/pkg/logutil/log_test.go b/pkg/logutil/log_test.go index b1480d0c9ba7..258a884227a0 100644 --- a/pkg/logutil/log_test.go +++ b/pkg/logutil/log_test.go @@ -20,7 +20,7 @@ import ( "github.com/coreos/pkg/capnslog" . "github.com/pingcap/check" - zap "github.com/pingcap/log" + zaplog "github.com/pingcap/log" log "github.com/sirupsen/logrus" ) @@ -70,7 +70,7 @@ func (s *testLogSuite) TestStringToLogFormatter(c *C) { // TestLogging assure log format and log redirection works. func (s *testLogSuite) TestLogging(c *C) { - conf := &zap.Config{Level: "warn", File: zap.FileLogConfig{}} + conf := &zaplog.Config{Level: "warn", File: zaplog.FileLogConfig{}} c.Assert(InitLogger(conf), IsNil) log.SetOutput(s.buf) @@ -95,6 +95,6 @@ func (s *testLogSuite) TestLogging(c *C) { } func (s *testLogSuite) TestFileLog(c *C) { - c.Assert(InitFileLog(&zap.FileLogConfig{Filename: "/tmp"}), NotNil) - c.Assert(InitFileLog(&zap.FileLogConfig{Filename: "/tmp/test_file_log", MaxSize: 0}), IsNil) + c.Assert(InitFileLog(&zaplog.FileLogConfig{Filename: "/tmp"}), NotNil) + c.Assert(InitFileLog(&zaplog.FileLogConfig{Filename: "/tmp/test_file_log", MaxSize: 0}), IsNil) } diff --git a/server/config.go b/server/config.go index 82511f4a6211..e1f3af3a10d8 100644 --- a/server/config.go +++ b/server/config.go @@ -24,9 +24,6 @@ import ( "strings" "time" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "github.com/BurntSushi/toml" "github.com/coreos/go-semver/semver" "github.com/pingcap/log" @@ -36,6 +33,8 @@ import ( "github.com/pkg/errors" "go.etcd.io/etcd/embed" "go.etcd.io/etcd/pkg/transport" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" ) // Config is the pd server configuration. diff --git a/server/server.go b/server/server.go index a7cc60e6f0b8..ec1190f02663 100644 --- a/server/server.go +++ b/server/server.go @@ -101,7 +101,7 @@ type Server struct { lastSavedTime time.Time // For async region heartbeat. hbStreams *heartbeatStreams - // For the logger + // Zap logger lg *zap.Logger logSyncer zapcore.WriteSyncer }