func setupLogging(token, env string, levels []log.Level) { log.SetFormatter(&log.TextFormatter{DisableTimestamp: true}) if token != "" { log.AddHook(&Hook{Client: roll.New(token, env), triggers: levels}) } }
// SetupLogging sets up logging. if token is not and empty string a rollbar // hook is added with the environment set to env. The log formatter is set to a // TextFormatter with timestamps disabled, which is suitable for use on Heroku. func SetupLogging(token, env string) { log.SetFormatter(&log.TextFormatter{DisableTimestamp: true}) if token != "" { log.AddHook(&Hook{Client: roll.New(token, env)}) } }
// recordRollbar records an error to the Rollbar aggregation service. func recordRollbar(err error) { client := roll.New(os.Getenv(RollbarTokenVariable), EnvProduction) _, rollbarErr := client.Error(err, map[string]string{}) if rollbarErr != nil { fmt.Printf("Got the error %v recording the error %v to Rollbar.\n", rollbarErr, err) } }
func TestTriggerLevels(t *testing.T) { client := roll.New("foobar", "testing") underTest := &Hook{Client: client} if !reflect.DeepEqual(underTest.Levels(), defaultTriggerLevels) { t.Fatal("Expected Levels() to return defaultTriggerLevels") } newLevels := []log.Level{log.InfoLevel} underTest.triggers = newLevels if !reflect.DeepEqual(underTest.Levels(), newLevels) { t.Fatal("Expected Levels() to return newLevels") } }
// ReportPanic attempts to report the panic to rollbar if the token is set func ReportPanic(token, env string) { if token != "" { h := &Hook{Client: roll.New(token, env)} h.ReportPanic() } }