mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: provide logging configuration
This commit is contained in:
parent
e3fa4587d9
commit
905b25655d
|
@ -14,6 +14,10 @@ func BootstrapEnvironmentLightweight(ctx context.Context, environ *Environment,
|
|||
return errors.Wrap(err, "exchange session configure error")
|
||||
}
|
||||
|
||||
if userConfig.Logging != nil {
|
||||
environ.SetLogging(userConfig.Logging)
|
||||
}
|
||||
|
||||
if userConfig.Persistence != nil {
|
||||
if err := ConfigurePersistence(ctx, userConfig.Persistence); err != nil {
|
||||
return errors.Wrap(err, "persistence configure error")
|
||||
|
@ -32,6 +36,10 @@ func BootstrapEnvironment(ctx context.Context, environ *Environment, userConfig
|
|||
return errors.Wrap(err, "exchange session configure error")
|
||||
}
|
||||
|
||||
if userConfig.Logging != nil {
|
||||
environ.SetLogging(userConfig.Logging)
|
||||
}
|
||||
|
||||
if userConfig.Persistence != nil {
|
||||
if err := ConfigurePersistence(ctx, userConfig.Persistence); err != nil {
|
||||
return errors.Wrap(err, "persistence configure error")
|
||||
|
|
|
@ -102,6 +102,8 @@ type Environment struct {
|
|||
syncStatus SyncStatus
|
||||
syncConfig *SyncConfig
|
||||
|
||||
loggingConfig *LoggingConfig
|
||||
|
||||
sessions map[string]*ExchangeSession
|
||||
}
|
||||
|
||||
|
@ -127,6 +129,10 @@ func (environ *Environment) Sessions() map[string]*ExchangeSession {
|
|||
return environ.sessions
|
||||
}
|
||||
|
||||
func (environ *Environment) SetLogging(config *LoggingConfig) {
|
||||
environ.loggingConfig = config
|
||||
}
|
||||
|
||||
func (environ *Environment) SelectSessions(names ...string) map[string]*ExchangeSession {
|
||||
if len(names) == 0 {
|
||||
return environ.sessions
|
||||
|
|
|
@ -261,10 +261,25 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
|
|||
}
|
||||
}
|
||||
|
||||
// add trade logger
|
||||
session.UserDataStream.OnTradeUpdate(func(trade types.Trade) {
|
||||
log.Info(trade.String())
|
||||
})
|
||||
if environ.loggingConfig != nil {
|
||||
if environ.loggingConfig.Trade {
|
||||
session.UserDataStream.OnTradeUpdate(func(trade types.Trade) {
|
||||
log.Info(trade.String())
|
||||
})
|
||||
}
|
||||
|
||||
if environ.loggingConfig.Order {
|
||||
session.UserDataStream.OnOrderUpdate(func(order types.Order) {
|
||||
log.Info(order.String())
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// if logging config is nil, then apply default logging setup
|
||||
// add trade logger
|
||||
session.UserDataStream.OnTradeUpdate(func(trade types.Trade) {
|
||||
log.Info(trade.String())
|
||||
})
|
||||
}
|
||||
|
||||
if viper.GetBool("debug-kline") {
|
||||
session.MarketDataStream.OnKLine(func(kline types.KLine) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user