mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
improve error logging
This commit is contained in:
parent
6b478b4e87
commit
87e5019b08
|
@ -3,6 +3,7 @@ package binance
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/c9s/bbgo/pkg/util"
|
"github.com/c9s/bbgo/pkg/util"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/adshao/go-binance"
|
"github.com/adshao/go-binance"
|
||||||
|
@ -38,7 +39,6 @@ type PrivateStream struct {
|
||||||
executionReportEventCallbacks []func(event *ExecutionReportEvent)
|
executionReportEventCallbacks []func(event *ExecutionReportEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *PrivateStream) dial(listenKey string) (*websocket.Conn, error) {
|
func (s *PrivateStream) dial(listenKey string) (*websocket.Conn, error) {
|
||||||
url := "wss://stream.binance.com:9443/ws/" + listenKey
|
url := "wss://stream.binance.com:9443/ws/" + listenKey
|
||||||
conn, _, err := websocket.DefaultDialer.Dial(url, nil)
|
conn, _, err := websocket.DefaultDialer.Dial(url, nil)
|
||||||
|
@ -111,7 +111,9 @@ func (s *PrivateStream) read(ctx context.Context, eventC chan interface{}) {
|
||||||
|
|
||||||
err := s.Client.NewKeepaliveUserStreamService().ListenKey(s.ListenKey).Do(ctx)
|
err := s.Client.NewKeepaliveUserStreamService().ListenKey(s.ListenKey).Do(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("listen key keep-alive error", err)
|
maskKey := s.ListenKey[0:5]
|
||||||
|
maskKey = maskKey + strings.Repeat("*", len(s.ListenKey)-1-5)
|
||||||
|
log.WithError(err).Errorf("listen key keep-alive error: %v key: %s", err, maskKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -2,8 +2,10 @@ package slack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/slack-go/slack"
|
"github.com/slack-go/slack"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SlackLogHook struct {
|
type SlackLogHook struct {
|
||||||
|
@ -36,19 +38,22 @@ func (t *SlackLogHook) Fire(e *logrus.Entry) error {
|
||||||
|
|
||||||
var slackAttachments []slack.Attachment = nil
|
var slackAttachments []slack.Attachment = nil
|
||||||
|
|
||||||
logerr, ok := e.Data["err"]
|
// error fields
|
||||||
if ok {
|
var fields []slack.AttachmentField
|
||||||
slackAttachments = append(slackAttachments, slack.Attachment{
|
for k, d := range e.Data {
|
||||||
Color: color,
|
fields = append(fields, slack.AttachmentField{
|
||||||
Title: "Error",
|
Title: k, Value: fmt.Sprintf("%v", d),
|
||||||
Fields: []slack.AttachmentField{
|
|
||||||
{Title: "Error", Value: logerr.(error).Error()},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slackAttachments = append(slackAttachments, slack.Attachment{
|
||||||
|
Color: color,
|
||||||
|
Title: strings.ToUpper(e.Level.String()),
|
||||||
|
Fields: fields,
|
||||||
|
})
|
||||||
|
|
||||||
_, _, err := t.Slack.PostMessageContext(context.Background(), t.ErrorChannel,
|
_, _, err := t.Slack.PostMessageContext(context.Background(), t.ErrorChannel,
|
||||||
slack.MsgOptionText(e.Message, true),
|
slack.MsgOptionText(":balloon: "+e.Message, true),
|
||||||
slack.MsgOptionAttachments(slackAttachments...))
|
slack.MsgOptionAttachments(slackAttachments...))
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user