示例#1
0
文件: rollrus.go 项目: tenex/rollrus
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})
	}
}
示例#2
0
文件: rollrus.go 项目: heroku/log-iss
// 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)})
	}
}
示例#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)
	}
}
示例#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")
	}
}
示例#5
0
文件: rollrus.go 项目: tenex/rollrus
// 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()
	}
}