Example #1
0
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})
	}
}
Example #2
0
// 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)})
	}
}
Example #3
0
// 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)
	}
}
Example #4
0
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")
	}
}
Example #5
0
// 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()
	}
}