Logging: structured slog messages throughout, and WithLogger options so callers choose the logger
Log messages are lower-case event names with their details as key/value
attributes ("error" for errors), in place of formatted strings.
Loggable package take a WithLogger option as part of their "New*" call,
defaulting to slog.Default(). Each tags its lines with its `component`.
Some debug loggers print directly rather than using slog when in
terminal logging mode.
This commit is contained in:
1 parent
0b5fde9563
commit
043e307663
49 files changed
+598
-248
No files matched your search
@@ -3,7 +3,6 @@ package fetcher
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
@@ -16,13 +15,14 @@ import (
|
||||
// runFindAOpportunity polls Find a Tender every configured interval until ctx
|
||||
// is cancelled.
|
||||
func runFindAOpportunity(
|
||||
ctx context.Context, conf *config.JobSearchConfig, since time.Time,
|
||||
ctx context.Context, logger *slog.Logger, conf *config.JobSearchConfig, since time.Time,
|
||||
) error {
|
||||
w := util.Worker{
|
||||
Logger: logger,
|
||||
Name: "FindAOpportunity",
|
||||
Interval: conf.Sources.FindATender.Interval,
|
||||
Task: func(ctx context.Context, since time.Time) error {
|
||||
return fetchFindAOpportunity(ctx, conf, since)
|
||||
return fetchFindAOpportunity(ctx, logger, conf, since)
|
||||
},
|
||||
}
|
||||
return w.Run(ctx, since)
|
||||
@@ -32,10 +32,10 @@ func runFindAOpportunity(
|
||||
// Tender. Finding nothing returns ErrNoNewReleases, so the worker still moves
|
||||
// its checkpoint on.
|
||||
func fetchFindAOpportunity(
|
||||
ctx context.Context, conf *config.JobSearchConfig, since time.Time,
|
||||
ctx context.Context, logger *slog.Logger, conf *config.JobSearchConfig, since time.Time,
|
||||
) error {
|
||||
opportunities, err := util.AwaitTask(ctx, func() ([]*types.Opportunity, error) {
|
||||
ft := findatender.New(conf, conf.Sources.FindATender.APIRoot)
|
||||
ft := findatender.New(conf, conf.Sources.FindATender.APIRoot, findatender.WithLogger(logger))
|
||||
defer ft.Shutdown()
|
||||
return ft.With(ctx).FetchAll(since, true)
|
||||
})
|
||||
@@ -46,7 +46,7 @@ func fetchFindAOpportunity(
|
||||
return err
|
||||
}
|
||||
|
||||
slog.Info(fmt.Sprintf("Found %d opportunities", len(opportunities)))
|
||||
logger.Info("fetched opportunities", "count", len(opportunities))
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user