Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #501 from erizocosmico/feature/replace-glog
Browse files Browse the repository at this point in the history
_scripts: replace glog with logrus
  • Loading branch information
ajnavarro authored Oct 25, 2018
2 parents 85cd592 + 6580302 commit 8831015
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
3 changes: 2 additions & 1 deletion _scripts/go-vitess/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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} && \
Expand Down
78 changes: 78 additions & 0 deletions _scripts/go-vitess/vt/log/log.go
Original file line number Diff line number Diff line change
@@ -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...)
}
)

0 comments on commit 8831015

Please sign in to comment.