bitget: refactor debug function tool

This commit is contained in:
c9s 2023-12-12 18:04:16 +08:00
parent b022a6119f
commit f3ce4c2cc6
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
"go.uber.org/multierr" "go.uber.org/multierr"
"golang.org/x/time/rate" "golang.org/x/time/rate"
@ -64,16 +65,31 @@ var (
kLineRateLimiter = rate.NewLimiter(rate.Every(time.Second/10), 5) kLineRateLimiter = rate.NewLimiter(rate.Every(time.Second/10), 5)
) )
var debugf func(msg string, args ...interface{}) type LogFunction func(msg string, args ...interface{})
func init() { var debugf LogFunction
func isPrefixFormatterConfigured() bool {
_, isPrefixFormatter := logrus.StandardLogger().Formatter.(*prefixed.TextFormatter)
return isPrefixFormatter
}
func getDebugFunction() LogFunction {
if v, ok := util.GetEnvVarBool("DEBUG_BITGET"); ok && v { if v, ok := util.GetEnvVarBool("DEBUG_BITGET"); ok && v {
debugf = func(msg string, args ...interface{}) { if isPrefixFormatterConfigured() {
return func(msg string, args ...interface{}) {
log.Infof("[BITGET] "+msg, args...) log.Infof("[BITGET] "+msg, args...)
} }
} else {
debugf = func(msg string, args ...interface{}) {}
} }
return log.Infof
}
return func(msg string, args ...interface{}) {}
}
func init() {
debugf = getDebugFunction()
} }
type Exchange struct { type Exchange struct {