diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index 5702ef8cad8..dd0da173f69 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 74e662813fe..40b832019c7 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ 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 diff --git a/go.sum b/go.sum index 4426a38899a..c814d022ef6 100644 --- a/go.sum +++ b/go.sum @@ -99,8 +99,8 @@ github.com/pingcap/gofail v0.0.0-20181217135706-6a951c1e42c3 h1:04yuCf5NMvLU8rB2 github.com/pingcap/gofail v0.0.0-20181217135706-6a951c1e42c3/go.mod h1:DazNTg0PTldtpsQiT9I5tVJwV1onHMKBBgXzmJUlMns= github.com/pingcap/kvproto v0.0.0-20181123124450-d48563486f61 h1:Yms1MiO/ezhE9ozwEOnlh/HrEFHX/r3fPCV6vNThGDM= 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= diff --git a/pkg/logutil/log_test.go b/pkg/logutil/log_test.go index b1480d0c9ba..258a884227a 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 82511f4a621..e1f3af3a10d 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 a7cc60e6f0b..ec1190f0266 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 }