repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
184f73a
parent
8e35e95
author
Eric Bower
date
2024-09-20 19:54:14 +0000 UTC
chore(feeds): more logging cleanup
1 files changed,  +10, -11
M feeds/cron.go
+10, -11
 1@@ -134,14 +134,14 @@ func (f *Fetcher) Validate(lastDigest *time.Time, parsed *shared.ListParsedText)
 2 }
 3 
 4 func (f *Fetcher) RunPost(logger *slog.Logger, user *db.User, post *db.Post) error {
 5-	logger.Info("running feed post", "user", user.Name, "filename", post.Filename)
 6+	logger.Info("running feed post", "filename", post.Filename)
 7 
 8 	parsed := shared.ListParseText(post.Text)
 9 
10-	logger.Info("last digest at", "user", user.Name, "lastDigest", post.Data.LastDigest)
11+	logger.Info("last digest at", "lastDigest", post.Data.LastDigest)
12 	err := f.Validate(post.Data.LastDigest, parsed)
13 	if err != nil {
14-		logger.Info(err.Error(), "user", user.Name)
15+		logger.Info("validation failed", "err", err.Error())
16 		return nil
17 	}
18 
19@@ -186,13 +186,13 @@ func (f *Fetcher) RunUser(user *db.User) error {
20 	}
21 
22 	if len(posts.Data) > 0 {
23-		logger.Info("found feed posts", "user", user.Name, "len", len(posts.Data))
24+		logger.Info("found feed posts", "len", len(posts.Data))
25 	}
26 
27 	for _, post := range posts.Data {
28 		err = f.RunPost(logger, user, post)
29 		if err != nil {
30-			logger.Info(err.Error(), "user", user)
31+			logger.Info("RunPost failed", "err", err.Error())
32 		}
33 	}
34 
35@@ -230,7 +230,7 @@ func (f *Fetcher) ParseURL(fp *gofeed.Parser, url string) (*gofeed.Feed, error)
36 }
37 
38 func (f *Fetcher) Fetch(logger *slog.Logger, fp *gofeed.Parser, url string, username string, feedItems []*db.FeedItem) (*Feed, error) {
39-	logger.Info("fetching feed", "user", username, "url", url)
40+	logger.Info("fetching feed", "url", url)
41 
42 	feed, err := f.ParseURL(fp, url)
43 	if err != nil {
44@@ -261,8 +261,7 @@ func (f *Fetcher) Fetch(logger *slog.Logger, fp *gofeed.Parser, url string, user
45 
46 	if len(items) == 0 {
47 		return nil, fmt.Errorf(
48-			"(%s) %s %w, skipping",
49-			username,
50+			"%s %w, skipping",
51 			url,
52 			ErrNoRecentArticles,
53 		)
54@@ -326,9 +325,9 @@ func (f *Fetcher) FetchAll(logger *slog.Logger, urls []string, inlineContent boo
55 		feedTmpl, err := f.Fetch(logger, fp, url, username, feedItems)
56 		if err != nil {
57 			if errors.Is(err, ErrNoRecentArticles) {
58-				logger.Info(err.Error())
59+				logger.Info("no recent articles", "err", err.Error())
60 			} else {
61-				logger.Error(err.Error())
62+				logger.Error("fetch error", "err", err.Error())
63 			}
64 			continue
65 		}
66@@ -389,7 +388,7 @@ func (f *Fetcher) SendEmail(logger *slog.Logger, username, email string, subject
67 	message := mail.NewSingleEmail(from, subject, to, msg.Text, msg.Html)
68 	client := sendgrid.NewSendClient(f.cfg.SendgridKey)
69 
70-	logger.Info("sending email digest", "user", username)
71+	logger.Info("sending email digest")
72 	response, err := client.Send(message)
73 	if err != nil {
74 		return err