improve logging

This commit is contained in:
c9s 2021-02-22 17:06:43 +08:00
parent 21a4669905
commit 73cb80ee96

View File

@ -497,7 +497,6 @@ func (environ *Environment) IsSyncing() (status SyncStatus) {
func (environ *Environment) setSyncing(status SyncStatus) { func (environ *Environment) setSyncing(status SyncStatus) {
environ.syncStatusMutex.Lock() environ.syncStatusMutex.Lock()
environ.syncStatus = status environ.syncStatus = status
log.Infof("setting sync status to %d", environ.syncStatus)
environ.syncStatusMutex.Unlock() environ.syncStatusMutex.Unlock()
} }
@ -566,11 +565,11 @@ func (environ *Environment) ConfigureNotificationSystem(userConfig *Config) erro
if len(slackToken) > 0 && userConfig.Notifications != nil { if len(slackToken) > 0 && userConfig.Notifications != nil {
if conf := userConfig.Notifications.Slack; conf != nil { if conf := userConfig.Notifications.Slack; conf != nil {
if conf.ErrorChannel != "" { if conf.ErrorChannel != "" {
log.Infof("found slack configured, setting up log hook...") log.Debugf("found slack configured, setting up log hook...")
log.AddHook(slacklog.NewLogHook(slackToken, conf.ErrorChannel)) log.AddHook(slacklog.NewLogHook(slackToken, conf.ErrorChannel))
} }
log.Infof("adding slack notifier with default channel: %s", conf.DefaultChannel) log.Debugf("adding slack notifier with default channel: %s", conf.DefaultChannel)
var notifier = slacknotifier.New(slackToken, conf.DefaultChannel) var notifier = slacknotifier.New(slackToken, conf.DefaultChannel)
environ.AddNotifier(notifier) environ.AddNotifier(notifier)
} }
@ -602,7 +601,7 @@ func (environ *Environment) ConfigureNotificationSystem(userConfig *Config) erro
if len(authToken) > 0 { if len(authToken) > 0 {
interaction.SetAuthToken(authToken) interaction.SetAuthToken(authToken)
log.Info("telegram bot auth token is set, using fixed token for authorization...") log.Debugf("telegram bot auth token is set, using fixed token for authorization...")
printTelegramAuthTokenGuide(authToken) printTelegramAuthTokenGuide(authToken)
} }
@ -689,25 +688,23 @@ func printOtpKey(key *otp.Key) {
} }
func printTelegramOtpAuthGuide(qrcodeImagePath string) { func printTelegramOtpAuthGuide(qrcodeImagePath string) {
log.Infof("To scan your OTP QR code, please run the following command:") fmt.Printf(`
log.Infof("") To scan your OTP QR code, please run the following command:
log.Infof("")
log.Infof(" open %s", qrcodeImagePath) open %s
log.Infof("")
log.Infof("") send the auth command with the generated one-time password to the bbgo bot you created to enable the notification:
log.Infof("send the auth command with the generated one-time password to the bbgo bot you created to enable the notification")
log.Infof("") /auth {code}
log.Infof("")
log.Infof(" /auth {code}") `, qrcodeImagePath)
log.Infof("")
log.Infof("")
} }
func printTelegramAuthTokenGuide(token string) { func printTelegramAuthTokenGuide(token string) {
fmt.Println("send the following command to the bbgo bot you created to enable the notification") fmt.Printf(`
fmt.Println("") send the following command to the bbgo bot you created to enable the notification:
fmt.Println("")
fmt.Printf(" /auth %s\n", token) /auth %s
fmt.Println("")
fmt.Println("") `, token)
} }