Beispiel #1
0
// Initializes program logging. Configures errors to go to Rollbar if a token
// was specified.
func initLog(forceTTY bool, environment, rollbarToken string) {
	log.SetFormatter(&log.TextFormatter{
		ForceColors: forceTTY,
	})

	// transmits to Rollbar on Error, Fatal, and Panic
	if environment != "" && rollbarToken != "" {
		rollrus.SetupLogging(rollbarToken, environment)

		log.WithFields(log.Fields{
			"environment": environment,
		}).Infof("Initialized Rollbar tracking with environment %v", environment)
	}
}
Beispiel #2
0
func main() {
	rollrus.SetupLogging(os.Getenv("ROLLBAR_TOKEN"), os.Getenv("ENVIRONMENT"))

	config, err := NewIssConfig()
	if err != nil {
		log.Fatalln(err)
	}

	log.AddHook(&DefaultFieldsHook{log.Fields{"app": "log-iss", "source": config.Deploy}})

	auth, err := authenticater.NewBasicAuthFromString(config.Tokens)
	if err != nil {
		log.Fatalln(err)
	}

	forwarderSet := newForwarderSet(config)

	shutdownCh := make(shutdownCh)
	httpServer := newHTTPServer(config, auth, fix, forwarderSet)

	go awaitShutdownSignals(httpServer.shutdownCh, shutdownCh)

	go forwarderSet.Run()

	go func() {
		if err := httpServer.Run(); err != nil {
			log.Fatalln("Unable to start HTTP server:", err)
		}
	}()

	if config.LibratoOwner != "" && config.LibratoToken != "" {
		log.WithField("source", config.LibratoSource).Info("starting librato metrics reporting")
		go librato.Librato(
			config.MetricsRegistry,
			20*time.Second,
			config.LibratoOwner,
			config.LibratoToken,
			config.LibratoSource,
			[]float64{0.50, 0.95, 0.99},
			time.Millisecond,
		)
	}

	log.WithField("at", "start").Info()
	<-shutdownCh
	log.WithField("at", "drain").Info()
	httpServer.Wait()
	log.WithField("at", "exit").Info()
}