From 658030286bab5e87357f59d007cceb53dd8e74ca Mon Sep 17 00:00:00 2001 From: Miguel Molina Date: Wed, 24 Oct 2018 16:28:54 +0200 Subject: [PATCH] _scripts: replace glog with logrus Signed-off-by: Miguel Molina --- _scripts/go-vitess/Makefile | 3 +- _scripts/go-vitess/vt/log/log.go | 78 ++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 _scripts/go-vitess/vt/log/log.go diff --git a/_scripts/go-vitess/Makefile b/_scripts/go-vitess/Makefile index d9bc4b606..f4f86e25e 100644 --- a/_scripts/go-vitess/Makefile +++ b/_scripts/go-vitess/Makefile @@ -19,7 +19,8 @@ filter-branch: clone cd ${VITESS_SRC} && \ git filter-branch --subdirectory-filter go && \ rm -fr README.md cacheservice cmd exit ioutil2 memcache race ratelimiter stats/influxdbbackend stats/opentsdb stats/prometheusbackend testfiles vtbench zk vt/mysqlctl/cephbackupstorage && \ - cp -f "${CWD}/doc.go" "${CWD}/README.md" "${CWD}/LICENSE" ${VITESS_SRC} + cp -f "${CWD}/doc.go" "${CWD}/README.md" "${CWD}/LICENSE" ${VITESS_SRC} && \ + cp -f "${CWD}/vt/log/log.go" "${VITESS_SRC}/vt/log/log.go" rename-packages: cd ${VITESS_SRC} && \ diff --git a/_scripts/go-vitess/vt/log/log.go b/_scripts/go-vitess/vt/log/log.go new file mode 100644 index 000000000..2d27ade29 --- /dev/null +++ b/_scripts/go-vitess/vt/log/log.go @@ -0,0 +1,78 @@ +// You can modify this file to hook up a different logging library instead of logrus. +// If you adapt to a different logging framework, you may need to use that +// framework's equivalent of *Depth() functions so the file and line number printed +// point to the real caller instead of your adapter function. + +package log + +import "github.com/sirupsen/logrus" + +// Level is used with V() to test log verbosity. +type Level = logrus.Level + +var ( + // V quickly checks if the logging verbosity meets a threshold. + V = func(level int) bool { + lvl := logrus.GetLevel() + switch level { + case 0: + return lvl == logrus.InfoLevel + case 1: + return lvl == logrus.WarnLevel + case 2: + return lvl == logrus.ErrorLevel + case 3: + return lvl == logrus.FatalLevel + default: + return false + } + } + + // Flush ensures any pending I/O is written. + Flush = func() {} + + // Info formats arguments like fmt.Print. + Info = logrus.Info + // Infof formats arguments like fmt.Printf. + Infof = logrus.Infof + // InfoDepth formats arguments like fmt.Print and uses depth to choose which call frame to log. + InfoDepth = func(_ int, args ...interface{}) { + logrus.Info(args...) + } + + // Warning formats arguments like fmt.Print. + Warning = logrus.Warning + // Warningf formats arguments like fmt.Printf. + Warningf = logrus.Warningf + // WarningDepth formats arguments like fmt.Print and uses depth to choose which call frame to log. + WarningDepth = func(depth int, args ...interface{}) { + logrus.Warning(args...) + } + + // Error formats arguments like fmt.Print. + Error = logrus.Error + // Errorf formats arguments like fmt.Printf. + Errorf = logrus.Errorf + // ErrorDepth formats arguments like fmt.Print and uses depth to choose which call frame to log. + ErrorDepth = func(_ int, args ...interface{}) { + logrus.Error(args...) + } + + // Exit formats arguments like fmt.Print. + Exit = logrus.Panic + // Exitf formats arguments like fmt.Printf. + Exitf = logrus.Panicf + // ExitDepth formats arguments like fmt.Print and uses depth to choose which call frame to log. + ExitDepth = func(_ int, args ...interface{}) { + logrus.Panic(args...) + } + + // Fatal formats arguments like fmt.Print. + Fatal = logrus.Fatal + // Fatalf formats arguments like fmt.Printf + Fatalf = logrus.Fatalf + // FatalDepth formats arguments like fmt.Print and uses depth to choose which call frame to log. + FatalDepth = func(_ int, args ...interface{}) { + logrus.Fatal(args...) + } +)