mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
Implement structured logging using log/slog package
This commit is contained in:
parent
54cb8fa028
commit
c0e954f19d
77 changed files with 1868 additions and 892 deletions
|
@ -238,7 +238,7 @@ func (s *Storage) RemoveCategory(userID, categoryID int64) error {
|
|||
func (s *Storage) RemoveAndReplaceCategoriesByName(userid int64, titles []string) error {
|
||||
tx, err := s.db.Begin()
|
||||
if err != nil {
|
||||
return errors.New("unable to begin transaction")
|
||||
return errors.New("store: unable to begin transaction")
|
||||
}
|
||||
|
||||
titleParam := pq.Array(titles)
|
||||
|
@ -247,11 +247,11 @@ func (s *Storage) RemoveAndReplaceCategoriesByName(userid int64, titles []string
|
|||
err = tx.QueryRow(query, userid, titleParam).Scan(&count)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return errors.New("unable to retrieve category count")
|
||||
return errors.New("store: unable to retrieve category count")
|
||||
}
|
||||
if count < 1 {
|
||||
tx.Rollback()
|
||||
return errors.New("at least 1 category must remain after deletion")
|
||||
return errors.New("store: at least 1 category must remain after deletion")
|
||||
}
|
||||
|
||||
query = `
|
||||
|
@ -268,14 +268,14 @@ func (s *Storage) RemoveAndReplaceCategoriesByName(userid int64, titles []string
|
|||
_, err = tx.Exec(query, userid, titleParam)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return fmt.Errorf("unable to replace categories: %v", err)
|
||||
return fmt.Errorf("store: unable to replace categories: %v", err)
|
||||
}
|
||||
|
||||
query = "DELETE FROM categories WHERE user_id = $1 AND title = ANY($2)"
|
||||
_, err = tx.Exec(query, userid, titleParam)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return fmt.Errorf("unable to delete categories: %v", err)
|
||||
return fmt.Errorf("store: unable to delete categories: %v", err)
|
||||
}
|
||||
tx.Commit()
|
||||
return nil
|
||||
|
|
|
@ -7,10 +7,10 @@ import (
|
|||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"miniflux.app/v2/internal/crypto"
|
||||
"miniflux.app/v2/internal/logger"
|
||||
"miniflux.app/v2/internal/model"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
@ -52,7 +52,10 @@ func (s *Storage) CountUnreadEntries(userID int64) int {
|
|||
|
||||
n, err := builder.CountEntries()
|
||||
if err != nil {
|
||||
logger.Error(`store: unable to count unread entries for user #%d: %v`, userID, err)
|
||||
slog.Error("Unable to count unread entries",
|
||||
slog.Int64("user_id", userID),
|
||||
slog.Any("error", err),
|
||||
)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -316,7 +319,11 @@ func (s *Storage) RefreshFeedEntries(userID, feedID int64, entries model.Entries
|
|||
|
||||
go func() {
|
||||
if err := s.cleanupEntries(feedID, entryHashes); err != nil {
|
||||
logger.Error(`store: feed #%d: %v`, feedID, err)
|
||||
slog.Error("Unable to cleanup entries",
|
||||
slog.Int64("user_id", userID),
|
||||
slog.Int64("feed_id", feedID),
|
||||
slog.Any("error", err),
|
||||
)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -463,7 +470,10 @@ func (s *Storage) MarkAllAsRead(userID int64) error {
|
|||
}
|
||||
|
||||
count, _ := result.RowsAffected()
|
||||
logger.Debug("[Storage:MarkAllAsRead] %d items marked as read", count)
|
||||
slog.Debug("Marked all entries as read",
|
||||
slog.Int64("user_id", userID),
|
||||
slog.Int64("nb_entries", count),
|
||||
)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -490,7 +500,10 @@ func (s *Storage) MarkGloballyVisibleFeedsAsRead(userID int64) error {
|
|||
}
|
||||
|
||||
count, _ := result.RowsAffected()
|
||||
logger.Debug("[Storage:MarkGloballyVisibleFeedsAsRead] %d items marked as read", count)
|
||||
slog.Debug("Marked globally visible feed entries as read",
|
||||
slog.Int64("user_id", userID),
|
||||
slog.Int64("nb_entries", count),
|
||||
)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -512,7 +525,11 @@ func (s *Storage) MarkFeedAsRead(userID, feedID int64, before time.Time) error {
|
|||
}
|
||||
|
||||
count, _ := result.RowsAffected()
|
||||
logger.Debug("[Storage:MarkFeedAsRead] %d items marked as read", count)
|
||||
slog.Debug("Marked feed entries as read",
|
||||
slog.Int64("user_id", userID),
|
||||
slog.Int64("feed_id", feedID),
|
||||
slog.Int64("nb_entries", count),
|
||||
)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -540,7 +557,11 @@ func (s *Storage) MarkCategoryAsRead(userID, categoryID int64, before time.Time)
|
|||
}
|
||||
|
||||
count, _ := result.RowsAffected()
|
||||
logger.Debug("[Storage:MarkCategoryAsRead] %d items marked as read", count)
|
||||
slog.Debug("Marked category entries as read",
|
||||
slog.Int64("user_id", userID),
|
||||
slog.Int64("category_id", categoryID),
|
||||
slog.Int64("nb_entries", count),
|
||||
)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -7,10 +7,8 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"miniflux.app/v2/internal/model"
|
||||
"miniflux.app/v2/internal/timer"
|
||||
)
|
||||
|
||||
// EntryPaginationBuilder is a builder for entry prev/next queries.
|
||||
|
@ -101,8 +99,6 @@ func (e *EntryPaginationBuilder) Entries() (*model.Entry, *model.Entry, error) {
|
|||
}
|
||||
|
||||
func (e *EntryPaginationBuilder) getPrevNextID(tx *sql.Tx) (prevID int64, nextID int64, err error) {
|
||||
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[EntryPaginationBuilder] %v, %v", e.conditions, e.args))
|
||||
|
||||
cte := `
|
||||
WITH entry_pagination AS (
|
||||
SELECT
|
||||
|
|
|
@ -7,11 +7,10 @@ import (
|
|||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"log/slog"
|
||||
"sort"
|
||||
|
||||
"miniflux.app/v2/internal/config"
|
||||
"miniflux.app/v2/internal/logger"
|
||||
"miniflux.app/v2/internal/model"
|
||||
)
|
||||
|
||||
|
@ -432,7 +431,11 @@ func (s *Storage) RemoveFeed(userID, feedID int64) error {
|
|||
return fmt.Errorf(`store: unable to read user feed entry ID: %v`, err)
|
||||
}
|
||||
|
||||
logger.Debug(`[FEED DELETION] Deleting entry #%d of feed #%d for user #%d (%d GoRoutines)`, entryID, feedID, userID, runtime.NumGoroutine())
|
||||
slog.Debug("Deleting entry",
|
||||
slog.Int64("user_id", userID),
|
||||
slog.Int64("feed_id", feedID),
|
||||
slog.Int64("entry_id", entryID),
|
||||
)
|
||||
|
||||
if _, err := s.db.Exec(`DELETE FROM entries WHERE id=$1 AND user_id=$2`, entryID, userID); err != nil {
|
||||
return fmt.Errorf(`store: unable to delete user feed entries #%d: %v`, entryID, err)
|
||||
|
|
|
@ -6,11 +6,11 @@ package storage // import "miniflux.app/v2/internal/storage"
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"miniflux.app/v2/internal/crypto"
|
||||
"miniflux.app/v2/internal/logger"
|
||||
"miniflux.app/v2/internal/model"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
@ -506,14 +506,20 @@ func (s *Storage) RemoveUser(userID int64) error {
|
|||
func (s *Storage) RemoveUserAsync(userID int64) {
|
||||
go func() {
|
||||
if err := s.deleteUserFeeds(userID); err != nil {
|
||||
logger.Error(`%v`, err)
|
||||
slog.Error("Unable to delete user feedd",
|
||||
slog.Int64("user_id", userID),
|
||||
slog.Any("error", err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
s.db.Exec(`DELETE FROM users WHERE id=$1`, userID)
|
||||
s.db.Exec(`DELETE FROM integrations WHERE user_id=$1`, userID)
|
||||
|
||||
logger.Debug(`[MASS DELETE] User #%d has been deleted (%d GoRoutines)`, userID, runtime.NumGoroutine())
|
||||
slog.Debug("User deleted",
|
||||
slog.Int64("user_id", userID),
|
||||
slog.Int("goroutines", runtime.NumGoroutine()),
|
||||
)
|
||||
}()
|
||||
}
|
||||
|
||||
|
@ -528,7 +534,11 @@ func (s *Storage) deleteUserFeeds(userID int64) error {
|
|||
var feedID int64
|
||||
rows.Scan(&feedID)
|
||||
|
||||
logger.Debug(`[USER DELETION] Deleting feed #%d for user #%d (%d GoRoutines)`, feedID, userID, runtime.NumGoroutine())
|
||||
slog.Debug("Deleting feed",
|
||||
slog.Int64("user_id", userID),
|
||||
slog.Int64("feed_id", feedID),
|
||||
slog.Int("goroutines", runtime.NumGoroutine()),
|
||||
)
|
||||
|
||||
if err := s.RemoveFeed(userID, feedID); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue