Skip to content

Commit

Permalink
fix(logging): don't duplicate manager group key
Browse files Browse the repository at this point in the history
I'd never realized this before, but `.With()` is append only, and so
re-adding a set of kvs under an existing group adds a second group with
the new entries -- it does not combine them in the json object or add
the keys to the existing group like I had for some reason thought.

This fixes that by only setting the kvs for that group once.
  • Loading branch information
tjhop committed Jul 16, 2024
1 parent 0deea8e commit 131237e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 1 addition & 8 deletions cmd/mango/mango.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,7 @@ func mango(ctx context.Context, logger *slog.Logger, inventoryPath, hostname str
inv.Reload(ctx, inventoryLogger)

// start manager, reload it with data from inventory, and then start a run of everything for the system
managerLogger := logger.With(
slog.String("worker", "manager"),
slog.Group(
"manager",
slog.String("inventory", inventoryPath),
slog.String("hostname", hostname),
),
)
managerLogger := logger.With(slog.String("worker", "manager"))
managerLogger.LogAttrs(
ctx,
slog.LevelInfo,
Expand Down
2 changes: 2 additions & 0 deletions internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func (mgr *Manager) ReloadAndRunAll(ctx context.Context, logger *slog.Logger, in
mLogger := logger.With(
slog.Group(
"manager",
slog.String("inventory", inv.GetInventoryPath()),
slog.String("hostname", inv.GetHostname()),
slog.Bool(string(contextKeyEnrolled), enrolled),
slog.String(string(contextKeyRunID), runID.String()),
),
Expand Down

0 comments on commit 131237e

Please sign in to comment.