From a2d595423e4270d8e644212021ba70c70df075d9 Mon Sep 17 00:00:00 2001 From: Maximilian Möhring Date: Tue, 14 May 2019 17:35:18 +0200 Subject: Refactores logging functions. (crawler) --- crawler/database.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'crawler/database.go') diff --git a/crawler/database.go b/crawler/database.go index 45f7fda..5de0fb2 100644 --- a/crawler/database.go +++ b/crawler/database.go @@ -122,15 +122,15 @@ func (app *App) save_offer(W []Angebot) error { o.error_msg = err.Error() o.error_ctx = fmt.Sprintf(`INSERT INTO angebot (shop, name, url, abv, volume, age, original_price, discounted_price, base_price, valid_until, image_url, spirit_type, created_at) VALUES (%d, "%s", "%s", %f, %f, %d, %d, %d, %d, %d, "%s", "%s", %d)`, o.Shop, o.Name, o.Url, o.Abv, o.Volume, o.Age, o.Original_price, o.Discounted_price, o.Base_price, o.Valid_until, o.Image_url, o.Spirit_type, app.Now) - WarnOffer(o, fmt.Sprintf("Save Offer: Inserting offer failed (%d)", found)) + o.Warn(fmt.Sprintf("Save Offer: Inserting offer failed (%d)", found)) } - DebugOffer(o, "database.go: Inserting offer.") + o.Debug("database.go: Inserting offer.") } else if err != nil { o.error_msg = err.Error() o.error_ctx = fmt.Sprintf(strings.Replace(detect_duplicate_query, "?", `"%s"`, 1), o.Name) - WarnOffer(o, "database.go: Duplicate query failed") + o.Warn("database.go: Duplicate query failed") } else { /* * If everything went right we update the image url to reflect new changes. @@ -140,13 +140,13 @@ func (app *App) save_offer(W []Angebot) error { if err != nil { o.error_msg = err.Error() o.error_ctx = fmt.Sprintf(`UPDATE _intern_view SET image_url = %s, website_raw = %s WHERE name = %s AND shop_id = %d AND volume = %4.2f AND abv = %4.2f AND original_price = %d AND discounted_price = %d AND valid_until = %d`, o.Image_url, "redacted", o.Name, o.Shop, o.Volume, o.Abv, o.Original_price, o.Discounted_price, o.Valid_until) - WarnOffer(o, "database.go: Preparing update_img_query failed") + o.Warn("database.go: Preparing update_img_query failed") } _, err = update_img_stmt.Exec(o.Image_url, o.Website, o.Name) if err != nil { o.error_msg = err.Error() o.error_ctx = fmt.Sprintf(`UPDATE _intern_view SET image_url = %s WHERE name = %s AND shop_id = %d AND volume = %4.2f AND abv = %4.2f AND original_price = %d AND discounted_price = %d AND valid_until = %d`, o.Image_url, o.Name, o.Shop, o.Volume, o.Abv, o.Original_price, o.Discounted_price, o.Valid_until) - WarnOffer(o, "database.go: Executing update_img_query failed") + o.Warn("database.go: Executing update_img_query failed") } } } @@ -179,17 +179,17 @@ func (app *App) remove_expired(W []Angebot, shop Shop) error { } if !app.offer_contains(W, offer_db) { - DebugOffer(offer_db, "Contains not - Set to expire") + offer_db.Debug("Contains not - Set to expire") expire_query := `UPDATE angebot SET valid_until = ? WHERE id = ?` _, err = app.DB.Exec(expire_query, app.Now, offer_db.Id) if err != nil { offer_db.error_msg = err.Error() offer_db.error_ctx = fmt.Sprintf("UPDATE angebot SET valid_until = %d WHERE id = %d", app.Now, offer_db.Id) - WarnOffer(offer_db, "Remove expired: Update failed") + offer_db.Warn("Remove expired: Update failed") return err } } - DebugOffer(offer_db, "Contains! DOES NOT EXPIRE!") + offer_db.Debug("Contains! DOES NOT EXPIRE!") } return nil -- cgit v1.2.3