Skip to content

Commit

Permalink
优化错误日志显示
Browse files Browse the repository at this point in the history
  • Loading branch information
buffge committed Mar 6, 2022
1 parent 4c9a1d9 commit cc6c442
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 11 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/avast/retry-go"
"github.com/getsentry/sentry-go"
"github.com/pkg/errors"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -92,7 +93,15 @@ func GetUserScore(summonerID int64) (*lcu.UserScore, error) {
return tmpErr
}, retry.Delay(time.Millisecond*10), retry.Attempts(5))
if err != nil {
logger.Error("获取游戏对局详细信息失败", zap.Error(err), zap.Int64("id", info.GameId))
sentry.WithScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelError)
scope.SetExtra("info", info)
scope.SetExtra("gameID", info.GameId)
scope.SetExtra("error", err.Error())
scope.SetExtra("errorVerbose", errors.Errorf("%+v", err))
sentry.CaptureMessage("获取游戏对局详细信息失败")
})
logger.Debug("获取游戏对局详细信息失败", zap.Error(err), zap.Int64("id", info.GameId))
return nil
}
mu.Lock()
Expand Down Expand Up @@ -121,7 +130,7 @@ func GetUserScore(summonerID int64) (*lcu.UserScore, error) {
for _, gameSummary := range gameSummaryList {
gameScore, err := calcUserGameScore(summonerID, gameSummary)
if err != nil {
logger.Error("游戏战绩计算用户得分失败", zap.Error(err), zap.Int64("summonerID", summonerID),
logger.Debug("游戏战绩计算用户得分失败", zap.Error(err), zap.Int64("summonerID", summonerID),
zap.Int64("gameID", gameSummary.GameId))
return userScoreInfo, nil
}
Expand Down
5 changes: 2 additions & 3 deletions prophet.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (p *Prophet) MonitorStart() {
p.initLcuClient(port, token)
err = p.initGameFlowMonitor(port, token)
if err != nil {
logger.Error("游戏流程监视器 err:", err)
logger.Debug("游戏流程监视器 err:", zap.Error(err))
}
p.lcuActive = false
p.currSummoner = nil
Expand Down Expand Up @@ -202,7 +202,6 @@ func (p *Prophet) initGameFlowMonitor(port int, authPwd string) error {
logger.Debug(fmt.Sprintf("connect to lcu %s", u.String()))
c, _, err := dialer.Dial(u.String(), header)
if err != nil {
logger.Error("连接到lcu ws 失败", zap.Error(err))
return err
}
defer c.Close()
Expand All @@ -226,7 +225,7 @@ func (p *Prophet) initGameFlowMonitor(port int, authPwd string) error {
msgType, message, err := c.ReadMessage()
if err != nil {
// log.Println("read:", err)
logger.Error("lol事件监控读取消息失败", zap.Error(err))
logger.Debug("lol事件监控读取消息失败", zap.Error(err))
return err
}
msg := &wsMsg{}
Expand Down

0 comments on commit cc6c442

Please sign in to comment.