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