Skip to content

chore: migrate log.Printf to log/slog in agent and cmd - #533

Merged
BaaRai merged 2 commits into
BaaRai:mainfrom
brixtonpham:chore/slog-agent
Nov 26, 2026
Merged

BaaRai merged 2 commits into
BaaRai:mainfrom
brixtonpham:chore/slog-agent

Conversation

@brixtonpham

Copy link
Copy Markdown
Contributor

Problem / Context

Follow-up to #488 (traffic/, egress/, enrich/, evidence/) and disjoint from #523 (llmpool/, llmrec/, intercept/, db/). All remaining non-test log.Printf/log.Print/log.Println calls in agent/ and cmd/ still used unstructured formatting instead of log/slog, so the logs view had to guess severity from message text instead of reading the slog level word directly.

Changes

  • Replaced all 26 log.Print/log.Printf call sites across 11 files in agent/ (assembly.go, compaction.go, coverage.go, noa.go, provider.go, spill.go, toolrag.go, tools.go, tools_insert.go, triage.go, worker.go) and all 13 non-fatal log.Printf/log.Println call sites across cmd/artex/main.go and cmd/artex-archive-check/main.go with log/slog (slog.Info, slog.Warn, slog.Error).
  • Preserved every existing [tag] prefix ([agent], [compaction], [config], [coverage], [insert_assets], [llm-test], [noa], [tool-rag], [tools], [triage]) so server/logsink.go parseLog keeps the tag badges and reads the exact slog level word directly.
  • Kept the three process-terminating log.Fatal/log.Fatalf calls in cmd/ unchanged.
  • Flattened the [llm-test] connection-attempt log (agent/provider.go) into structured single-line attributes (response_body via clipBody) and structured [noa] diagnostics as a quoted msg attribute.
  • Added agent/slog_test.go verifying [tag] and slog level preservation through log.Default().

Testing

  • gofmt -l agent/ cmd/ — clean
  • Verified 0 remaining log.Print* calls in non-test agent/ and cmd/ files
  • go build ./... — passed
  • go vet ./... — passed
  • go test -race -p 1 ./agent ./cmd/... — passed (agent, cmd/artex; Postgres-dependent tests skipped without ARTEX_PG_DSN)
  • go test -p 1 ./server -run TestParseLog — passed

@5P34R

5P34R commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Review notes

Almost ready. No secrets are newly logged and log.Fatalf("serve…") and the return 1 paths in cmd/artex/main.go are kept. It touches different files from #536 and #523, and its agent/provider.go hunk applies cleanly alongside #538.

Required: [config] snapshot {json} becomes snapshot config="{\"…\"}", escaped on one line. docs/OPS.md:25 documents the old form, and grep/parse tooling relying on it breaks. Either update the doc or keep the raw JSON in the message.

Nits: the panic stack trace in agent/assembly.go also becomes a single escaped line. The new agent/slog_test.go swaps the global log output, so stray goroutines logging during the test could make it flaky.

@brixtonpham

Copy link
Copy Markdown
Contributor Author

Addressed all three points in d880eb2:

  • [config] snapshot (cmd/artex/main.go): kept raw unescaped JSON in the message (slog.Info("[config] snapshot " + string(b))) so it stays compatible with docs/OPS.md:25 and existing grep/parse tooling.
  • Panic stack trace (agent/assembly.go): kept the formatted multi-line stack trace in the slog.Error message instead of an escaped single-line attribute.
  • agent/slog_test.go: switched to a mutex-guarded slog.Handler via slog.SetDefault matching on the specific [noa] and [llm-test] records, avoiding global log.SetOutput mutation and stray-goroutine flakiness.

@BaaRai
BaaRai merged commit 3a24d1d into BaaRai:main Nov 26, 2026
6 checks passed
@BaaRai

BaaRai commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Merged, thanks @brixtonpham. Verified on current main with its tests and negative control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants