package main import ( "flag" log "github.com/Sirupsen/logrus" ) // global config, gets overwritten by main var _conf Config func init() { // we need to parse the config because of log level setting configFile := flag.String("config", "", "path to config file") flag.Parse() _conf.parseConfig(*configFile) if _conf.Debug { log.SetLevel(log.DebugLevel) } else { log.SetLevel(log.WarnLevel) } } func Fatal(err error, msg string) { log.WithFields( log.Fields{ "error": err.Error(), }, ).Fatal(msg) } func Println(err error, msg string) { if err != nil { log.WithFields( log.Fields{ "error": err.Error(), }, ).Println(msg) } else { log.Println(msg) } } func PrintlnOffer(offer Angebot, msg string) { log.WithFields( log.Fields{ "Name": offer.Name, "Shop": offer.Shop, "ABV": offer.Abv, "Volume": offer.Volume, "Url": offer.Url, "Original Price": offer.Original_price, "Discounted Price": offer.Discounted_price, "Base Price": offer.Base_price, "Image_url": offer.Image_url, "Spirit Type": offer.Spirit_type, "Valid Until": offer.Valid_until, }, ).Println(msg) } func Debug(err error, msg string) { if err != nil { log.WithFields( log.Fields{ "error": err.Error(), }, ).Debug(msg) } else { log.Debug(msg) } } func DebugOffer(offer Angebot, msg string) { log.WithFields( log.Fields{ "Name": offer.Name, "Shop": offer.Shop, "ABV": offer.Abv, "Volume": offer.Volume, "Url": offer.Url, "Original Price": offer.Original_price, "Discounted Price": offer.Discounted_price, "Base Price": offer.Base_price, "Image_url": offer.Image_url, "Spirit Type": offer.Spirit_type, "Valid Until": offer.Valid_until, }, ).Debug(msg) }