Example #1
0
File: alert.go Project: enova/tokyo
// Configure Log-File
func setLogFile(cfg *cfg.Config) {

	// Construct Log-File Path
	dir := cfg.Get("Dir")
	_, app := filepath.Split(os.Args[0])
	now := time.Now().Format("20060102_150405_000")
	pid := os.Getpid()
	filename := fmt.Sprintf("%s/%s_%s_%d.log", dir, app, now, pid)

	// Create Directory
	err := os.MkdirAll(dir, 0755)
	if err != nil {
		Cerr("Alert: Can't create log directory: " + dir)
		os.Exit(1)
	}

	// Append Log-File
	logFile, err = os.OpenFile(filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
	if err != nil {
		Cerr("Alert: Can't append file: " + filename + ", " + err.Error())
		os.Exit(1)
	}

	Cerr("LogFile: " + filename)
}
Example #2
0
File: alert.go Project: enova/tokyo
// Configure Sentry
func setSentry(cfg *cfg.Config) {
	var err error

	// URL (From Env)
	url := os.Getenv("SENTRY_DSN")

	// Overwrite With Config URL
	if cfg.Has("DSN") {
		url = cfg.Get("DSN")
	}

	// Tags
	tags := make(map[string]string)
	tags["user"] = username()
	tags["app"] = os.Args[0]
	tags["cmd"] = strings.Join(os.Args, " ")
	tags["pid"] = fmt.Sprintf("%d", os.Getpid())

	// Custom-Tags
	for t := 0; t < cfg.Size("Tag"); t++ {
		line := cfg.GetN(t, "Tag")
		tokens := strings.Fields(line)

		// Invalid Tag
		if len(tokens) < 2 {
			Cerr("Tag should have at least two tokens - key value..., " + line)
			continue
		}

		// Add Tag
		key := tokens[0]
		val := strings.Join(tokens[1:], " ")
		tags[key] = val
	}

	// Create Sentry-Client
	sentry, err = raven.NewWithTags(url, tags)
	if err != nil {
		log.Fatal(err)
	}

	Cerr("Sentry: " + tagsToS(tags))
}
Example #3
0
File: alert.go Project: enova/tokyo
// Set configures the alert settings
func Set(cfg *cfg.Config) {

	// Configure: Sentry-Client
	if cfg.Has("Alert.Sentry.Use") {

		// Use
		use := cfg.Get("Alert.Sentry.Use")
		if use == "true" || use == "True" {
			sentryCfg := cfg.Descend("Alert.Sentry")
			setSentry(sentryCfg)
		}
	}

	// Configure: Log-File
	if cfg.Has("Alert.LogFile.Use") {

		// Use
		use := cfg.Get("Alert.LogFile.Use")
		if use == "true" || use == "True" {
			logFileCfg := cfg.Descend("Alert.LogFile")
			setLogFile(logFileCfg)
		}
	}
}