问题:当我尝试使用错误报告功能记录错误时,它不会发送到错误报告器。这是文档我这样实例化:const projectID = "correct-project-id"var ErrorClient *errorreporting.Clientfunc MakeErrorReporter() { var err error ctx := context.Background() ErrorClient, err = errorreporting.NewClient(ctx, projectID, errorreporting.Config{ ServiceName: "easyLanding", OnError: func(err error) { log.Printf("Could not log error: %v", err) }, }) if err != nil { msg := fmt.Sprintf("this is the fatal err", err.Error()) log.Fatal(msg) } defer ErrorClient.Close()}然后我这样称呼它:func LogErr(err error, location string, userId uint) string { errCode := RandStringRunes(4) msg := fmt.Sprintf("Code: %v | Error: %v | Location: %v", errCode, err.Error(), location) var email string if userId == 0 { email = "system" } else { email, _ = GetUserEmail(userId) } if viper.GetString("debug") == "false" { logger.Logger.Error().Msgf("Just ran the error with client %v", errorReporting.ErrorClient.Report) if errorReporting.ErrorClient == nil { logger.Logger.Error().Msg("Error client is nil") } else { logger.Logger.Error().Msg("Error client is NOT nil") } email = fmt.Sprintf("%s - %s", email, location) errorReporting.ErrorClient.Report(errorreporting.Entry{ Error: err, User: email, }) label := map[string]string{} label["key"] = "simpleMessage" logger.InfoLogger.Log(logging.Entry{ Severity: logging.Info, Payload: msg, Labels: label, InsertID: "", }) } else { logger.Logger.Error().Msg(msg) logger.Logger.Error().Msg(email) } return errCode}日志Error client is NOT nil运行,所以我知道它已经启动,但没有出现任何警报。我还通过一个特殊的 URL 端点触发它,该端点在每次点击时记录一个错误(或应该)。
1 回答
宝慕林4294392
TA贡献2021条经验 获得超8个赞
我在我这边使用了你的代码,一切都按预期工作,如果你在 GCP 控制台上看不到任何错误,这表明错误报告 API 未启用,因此你看不到任何错误。
- 1 回答
- 0 关注
- 125 浏览
添加回答
举报
0/150
提交
取消