diff --git a/cmd/shigola/cmd/cache/seed_purge.go b/cmd/shigola/cmd/cache/seed_purge.go index 13908b26..5b1f66a7 100644 --- a/cmd/shigola/cmd/cache/seed_purge.go +++ b/cmd/shigola/cmd/cache/seed_purge.go @@ -438,8 +438,8 @@ func seedPurgeCommand(_ *cobra.Command, _ []string) (err error) { } }() - log.Info("zoom list: ", zooms) - log.Info("tile matrix set: ", seedPurgeGrid.ID()) + log.Info("zoom list:", zooms) + log.Info("tile matrix set:", seedPurgeGrid.ID()) tileChannel := generateTilesForBounds(ctx, seedPurgeBounds, zooms, seedPurgeGrid) return doWork(ctx, tileChannel, seedPurgeMaps, cacheConcurrency, seedPurgeWorker) diff --git a/cmd/shigola/cmd/cache/tile_list.go b/cmd/shigola/cmd/cache/tile_list.go index e99d82c4..5bd8d317 100644 --- a/cmd/shigola/cmd/cache/tile_list.go +++ b/cmd/shigola/cmd/cache/tile_list.go @@ -88,7 +88,7 @@ func tileListCommand(cmd *cobra.Command, args []string) (err error) { defer tileListFile.Close() } - log.Info("zoom list: ", zooms) + log.Info("zoom list:", zooms) tilechannel := generateTilesForTileList(ctx, in, explicit, zooms, format) diff --git a/cmd/shigola/cmd/cache/tile_name.go b/cmd/shigola/cmd/cache/tile_name.go index 4e8a6224..0100d730 100644 --- a/cmd/shigola/cmd/cache/tile_name.go +++ b/cmd/shigola/cmd/cache/tile_name.go @@ -71,7 +71,7 @@ func tileNameCommand(cmd *cobra.Command, args []string) (err error) { } }() - log.Info("zoom list: ", zooms) + log.Info("zoom list:", zooms) tilechannel := generateTilesForTileName(ctx, tileNameTile, explicit, zooms) // start up workers diff --git a/internal/log/README.md b/internal/log/README.md index e0958c6b..f728200f 100644 --- a/internal/log/README.md +++ b/internal/log/README.md @@ -69,3 +69,6 @@ the call sites inherited from tegola, and log through `slog.Default()`: All of them attach the first non-nil `error` among their arguments under `err`, so `log.Errorf("tier get: %v", err)` produces both a readable message and a structured error. A disabled level returns before formatting anything. + +`fmt.Println` puts a space between every pair of operands, so a message passed to +`Error`, `Warn`, `Info` or `Debug` should not end in one: `log.Info("zoom list:", zooms)`. diff --git a/internal/log/format_test.go b/internal/log/format_test.go index ad3c0f20..417a5c4b 100644 --- a/internal/log/format_test.go +++ b/internal/log/format_test.go @@ -236,10 +236,10 @@ func TestWrappers(t *testing.T) { wantMsg: "boom", wantErr: "boom", }, - // Operands are separated as Println separates them — always by a - // space — which reads right for the call sites that pass a message - // and a value, and doubles the space where the message already ends - // in one ("zoom list: ", zooms). + // Operands are separated as Println separates them, always by a + // space. That reads right for a message and a value, and doubles the + // space where the message already ends in one, which is why no call + // site's message does. "a message and a value": { emit: func() { log.Info("zoom list:", []int{0, 1}) }, wantMsg: "zoom list: [0 1]", diff --git a/internal/log/log.go b/internal/log/log.go index 67e6c3a3..14700e01 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -292,9 +292,14 @@ func Debugf(format string, args ...any) { } // Error, Warn, Info and Debug format their operands as fmt.Sprintln does, -// without the newline: the call sites were written against that -// ("zoom list: ", zooms), and against an error on its own, which Println -// renders as its message. +// without the newline. The call sites pass operands — usually a message, a +// message and a value ("zoom list:", zooms), or an error on its own, which +// Println renders as its message. Println always separates operands with a +// space, so a message must not end in one. +// +// fmt.Sprint was the other candidate, and would have spared the call sites +// written as ("zoom list: ", zooms), but it puts no space next to a string +// operand: ("could not purge", err) would have read "could not purgeboom". // // They used to pass args[0].(string) to slog as the message and all of args as // attributes, so a non-string first argument — log.Error(err) — panicked, and