summaryrefslogtreecommitdiff
path: root/crawler/log.go
diff options
context:
space:
mode:
authorhorus2018-02-16 16:57:10 +0100
committerhorus2018-02-16 16:57:39 +0100
commited6ab4da59f80bf9fa2cbf15da5c9167dff44ea4 (patch)
tree1038ab5d9b2a0b9bde5ee021624fa87422b705f8 /crawler/log.go
parentb131ce750740ddb9c47515727327c06aa0d22aad (diff)
downloadalkobote-ed6ab4da59f80bf9fa2cbf15da5c9167dff44ea4.tar.gz
Adds structured logging. (crawler)
Diffstat (limited to 'crawler/log.go')
-rw-r--r--crawler/log.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/crawler/log.go b/crawler/log.go
new file mode 100644
index 0000000..4b9f374
--- /dev/null
+++ b/crawler/log.go
@@ -0,0 +1,79 @@
+package main
+
+import (
+ log "github.com/Sirupsen/logrus"
+)
+
+func init() {
+ log.SetLevel(log.DebugLevel)
+}
+
+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)
+}