-2

rollbar.com 网站上有一个示例 Go 代码,它应该说明应该如何将日志项发送到 Rollbar:

package main

import (
  "github.com/rollbar/rollbar-go"
)

func main() {
  rollbar.SetToken("6a...16")
  rollbar.SetEnvironment("production")                 // defaults to "development"
  rollbar.SetCodeVersion("v2")                         // optional Git hash/branch/tag (required for GitHub integration)
  rollbar.SetServerHost("web.1")                       // optional override; defaults to hostname
  rollbar.SetServerRoot("github.com/heroku/myproject") // path of project (required for GitHub integration and non-project stacktrace collapsing)

  result, err := DoSomething()
  if err != nil {
    rollbar.Critical(err)
  }

  rollbar.Info("Message body goes here")

  rollbar.Wait()
}

不幸的是,这段代码无法编译,因为被调用的DoSomething函数不存在。但即使我解决了这个问题并创建了一个名为DoSomethingthen 的函数,它仍然不会将任何内容记录到 Rollbar 中。

我应该如何从 Go 代码登录到 Rollbar?

4

1 回答 1

0

这是一个从 Go 代码登录到 Rollbar 的接近最小的代码:

package main

import (
    "github.com/rollbar/rollbar-go"
    "time"
)

func main() {
    rollbar.SetToken("7135d6a90b1c4a6d9dbc736fb97d3816")
    rollbar.SetEnvironment("production")                 // defaults to "development"

    rollbar.Info("Message body goes here")
    rollbar.WrapAndWait(DoSomething)
}

func DoSomething() {
    var timer *time.Timer = nil
    timer.Reset(10) // this will panic
}
于 2020-06-09T07:40:10.307 回答