summaryrefslogtreecommitdiff
path: root/crawler/log.go
diff options
context:
space:
mode:
authorMaximilian Möhring2019-05-15 16:58:56 +0200
committerMaximilian Möhring2019-05-15 16:58:56 +0200
commitc9afd4e8afe6a719b5d930c9baa2699442849fd8 (patch)
tree3eb127ab39e8cacabef7c82a264f18ce4b8ee321 /crawler/log.go
parent428ed1c35be88fbfedc1569d6e9692778c89ff25 (diff)
downloadalkobote-c9afd4e8afe6a719b5d930c9baa2699442849fd8.tar.gz
Improves structured logging. (crawler)
Diffstat (limited to 'crawler/log.go')
-rw-r--r--crawler/log.go96
1 files changed, 60 insertions, 36 deletions
diff --git a/crawler/log.go b/crawler/log.go
index 111df53..e9481cb 100644
--- a/crawler/log.go
+++ b/crawler/log.go
@@ -4,6 +4,32 @@ import (
log "github.com/sirupsen/logrus"
)
+func (offer Angebot) getFields() log.Fields {
+ return 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,
+ "Error Msg": offer.error_msg,
+ "Error Ctx": offer.error_ctx,
+ }
+}
+
+func (shop Shop) getFields() log.Fields {
+ return log.Fields{
+ "Name": shop.Name,
+ "Error Msg": shop.error_msg,
+ "Error Ctx": shop.error_ctx,
+ }
+}
+
func Fatal(err error, msg string) {
if err != nil {
log.WithFields(
@@ -15,9 +41,33 @@ func Fatal(err error, msg string) {
log.Fatal(msg)
}
}
+
func (offer Angebot) Fatal(msg string) {
log.WithFields(offer.getFields()).Fatal(msg)
}
+func (shop Shop) Fatal(msg string) {
+ log.WithFields(shop.getFields()).Fatal(msg)
+}
+
+func Warn(err error, msg string) {
+ if err != nil {
+ log.WithFields(
+ log.Fields{
+ "error": err.Error(),
+ },
+ ).Warn(msg)
+ } else {
+ log.Warn(msg)
+ }
+}
+
+func (offer Angebot) Warn(msg string) {
+ log.WithFields(offer.getFields()).Warn(msg)
+}
+
+func (shop Shop) Warn(msg string) {
+ log.WithFields(shop.getFields()).Warn(msg)
+}
func Println(err error, msg string) {
if err != nil {
@@ -32,10 +82,13 @@ func Println(err error, msg string) {
}
func (offer Angebot) Println(msg string) {
-
log.WithFields(offer.getFields()).Println(msg)
}
+func (shop Shop) Println(msg string) {
+ log.WithFields(shop.getFields()).Println(msg)
+}
+
func Debug(err error, msg string) {
if err != nil {
log.WithFields(
@@ -49,10 +102,13 @@ func Debug(err error, msg string) {
}
func (offer Angebot) Debug(msg string) {
-
log.WithFields(offer.getFields()).Debug(msg)
}
+func (shop Shop) Debug(msg string) {
+ log.WithFields(shop.getFields()).Debug(msg)
+}
+
func Trace(err error, msg string) {
if err != nil {
log.WithFields(
@@ -66,41 +122,9 @@ func Trace(err error, msg string) {
}
func (offer Angebot) Trace(msg string) {
-
log.WithFields(offer.getFields()).Trace(msg)
}
-func (offer Angebot) Warn(msg string) {
-
- log.WithFields(offer.getFields()).Warn(msg)
-}
-
-func (offer Angebot) getFields() log.Fields {
- return 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,
- "Error_msg": offer.error_msg,
- "Error_ctx": offer.error_ctx,
- }
-}
-
-func Warn(err error, msg string) {
- if err != nil {
- log.WithFields(
- log.Fields{
- "error": err.Error(),
- },
- ).Warn(msg)
- } else {
- log.Warn(msg)
- }
+func (shop Shop) Trace(msg string) {
+ log.WithFields(shop.getFields()).Trace(msg)
}