Iker Narvaez

Refactor package & improve error logging

package error_reporter
import(
"time"
"log"
"os"
"git.ukko.mx/ukko/influx_client_go.git"
)
var(
defaultUsername = os.Getenv("INFLUX_USERNAME")
defaultPassword = os.Getenv("INFLUX_PASSWORD")
defaultDbAddress = os.Getenv("INFLUX_DB_ADDRESS")
defaultSeries = "errors"
influxClient *influx_client.InfluxClient
series string
)
func InitReporting(db string, username string, password string, dbAddress string) {
influxClient = influx_client.CreateClient(db, username, password, dbAddress)
series = defaultSeries
}
func InitDefaultReporting(db string) {
influxClient = influx_client.CreateClient(db, defaultUsername, defaultPassword, defaultDbAddress)
series = defaultSeries
}
func Report(who string, message string, err error) {
log.Fatalf("%s: %s", message, err)
tags := errorSystemTags(who, message, err)
fields := map[string]interface{}{
"value": 1,
}
stamp := time.Now()
influxClient.CreatePoint(series, tags, fields, stamp)
}
func errorSystemTags(who string, message string, err error) map[string]string {
host, _:= os.Hostname()
return map[string]string{
"hostname": host,
"process": who,
"message": message,
"exception": err.Error(),
}
}