summaryrefslogtreecommitdiff
path: root/crawler/log.go
blob: 26f4abd5593ddc065155ef1c576088d312c24448 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main

import (
	log "github.com/sirupsen/logrus"
)

func Fatal(err error, msg string) {
	if err != nil {
		log.WithFields(
			log.Fields{
				"error": err.Error(),
			},
		).Fatal(msg)
	} else {
		log.Fatal(msg)
	}
}
func (offer Angebot) Fatal(msg string) {
	log.WithFields(offer.getFields()).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 (offer Angebot) Println(msg string) {

	log.WithFields(offer.getFields()).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 (offer Angebot) Debug(msg string) {

	log.WithFields(offer.getFields()).Debug(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)
	}
}