add fields to slack notifier logs

This commit is contained in:
c9s 2020-10-28 17:34:12 +08:00
parent b22e0370b3
commit c96845ff6a

View File

@ -4,7 +4,7 @@ import (
"context"
"fmt"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/slack-go/slack"
)
@ -69,13 +69,15 @@ func (n *Notifier) NotifyTo(channel, format string, args ...interface{}) {
nonSlackArgs = args[:slackArgsOffset]
}
logrus.Infof(format, nonSlackArgs...)
log.Infof(format, nonSlackArgs...)
_, _, err := n.client.PostMessageContext(context.Background(), channel,
slack.MsgOptionText(fmt.Sprintf(format, nonSlackArgs...), true),
slack.MsgOptionAttachments(slackAttachments...))
if err != nil {
logrus.WithError(err).Errorf("slack error: %s", err.Error())
log.WithError(err).
WithField("channel", channel).
Errorf("slack error: %s", err.Error())
}
return