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:
bwilliams committed 2026-10-15 16:10:52 +01:00
1 parent 0b5fde9563
commit 043e307663
49 files changed
+598 -248

No files matched your search

+3 -1
View File
@@ -2,6 +2,7 @@ package fetcher
import (
"context"
"log/slog"
"time"
"git.avsdev.uk/Go/job-search/internal/config"
@@ -14,10 +15,11 @@ const sleepDuration = 60 * time.Second
// runSleeper runs the sleeper test source until ctx is cancelled: every
// configured interval it simulates work by sleeping for sleepDuration.
func runSleeper(
ctx context.Context, conf *config.JobSearchConfig, since time.Time,
ctx context.Context, logger *slog.Logger, conf *config.JobSearchConfig, since time.Time,
) error {
blockShutdown := conf.Sources.Sleeper.BlockShutdown
w := util.Worker{
Logger: logger,
Name: "Sleeper",
Interval: conf.Sources.Sleeper.Interval,
Task: func(taskCtx context.Context, since time.Time) error {