mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
bitget: refactor debug function tool
This commit is contained in:
parent
b022a6119f
commit
f3ce4c2cc6
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user