Skip to content

feat(logging): add .With() system identifiers to all top-level loggers#1191

Open
corylanou wants to merge 4 commits intomainfrom
issue-1189-feat-logging-add-with-system-identifiers-to-all-top-level-lo
Open

feat(logging): add .With() system identifiers to all top-level loggers#1191
corylanou wants to merge 4 commits intomainfrom
issue-1189-feat-logging-add-with-system-identifiers-to-all-top-level-lo

Conversation

@corylanou
Copy link
Collaborator

Description

Add structured logging context (.With()) to all top-level loggers so every log line self-identifies its source system and subsystem. This makes debugging multi-database setups significantly easier.

Resulting log hierarchy:

Store:       system=store
  └─ DB:       system=store db=mydb.sqlite
      └─ Compactor:  system=store db=mydb.sqlite subsystem=compactor
      └─ WALReader:  system=store db=mydb.sqlite subsystem=wal-reader
      └─ Replica:    system=store db=mydb.sqlite replica=s3
          └─ Client: system=store db=mydb.sqlite replica=s3 [s3 group]
Server:      system=server

Example log output: level=INFO msg="compacted snapshots" system=store db=mydb.sqlite subsystem=compactor

Changes by tier:

  • Tier 0: Fix remaining Allow store logger to be configured and update some references to slog default logger #1179 changes — 3 slog.Debugdb.Logger.Debug in verify()
  • Tier 1: Store logger tagged system=store, Server tagged system=server
  • Tier 1.5: DB.SetLogger() propagates store logger with db=<name> to DB and compactor; called in NewStore and RegisterDB
  • Tier 2: Compactor gets subsystem=compactor, WALReader gets subsystem=wal-reader
  • Tier 3: All 8 replica clients + S3 Leaser gain SetLogger() for logger propagation via anonymous interface assertion

Motivation and Context

After #1178 fixed default slog usage, log lines still don't self-identify which system/subsystem produced them. In multi-database setups, it's difficult to correlate log lines to specific databases or subsystems. This also subsumes the remaining db.go changes from PR #1179.

Fixes #1189

How Has This Been Tested?

  • go build ./... — passes
  • go test ./... — all tests pass (including existing store/compactor/replica tests)
  • go vet ./... — clean
  • Pre-commit hooks (go-imports, go-vet, go-staticcheck) — all pass

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (would cause existing functionality to not work as expected)

Checklist

  • My code follows the code style of this project (go fmt, go vet)
  • I have tested my changes (go test ./...)
  • I have updated the documentation accordingly (if needed)

Add structured logging context so every log line self-identifies its
source system, making multi-database debugging easier.

- Store logger tagged with system=store, Server with system=server
- DB loggers inherit store logger with db=<name> attribute
- Compactor and WALReader get subsystem= attributes
- All 8 replica clients gain SetLogger() for logger propagation
- Fix remaining slog.Debug → db.Logger.Debug in verify()

Resulting log hierarchy:
  Store: system=store
    DB: system=store db=mydb.sqlite
      Compactor: system=store db=mydb.sqlite subsystem=compactor
      WALReader: system=store db=mydb.sqlite subsystem=wal-reader
      Replica: system=store db=mydb.sqlite replica=s3
        Client: system=store db=mydb.sqlite replica=s3 [s3 group]
  Server: system=server

Fixes #1189
@github-actions
Copy link

github-actions bot commented Mar 10, 2026

PR Build Metrics

All clear — no issues detected

Check Status Summary
Binary size 35.91 MB (+4.0 KB / +0.01%)
Dependencies No changes
Vulnerabilities None detected
Go toolchain 1.25.8 (latest)
Module graph 1204 edges (0)

Binary Size

Size Change
Base (d514bc7) 35.90 MB
PR (1b83171) 35.91 MB +4.0 KB (+0.01%)

Dependency Changes

No dependency changes.

govulncheck Output

No vulnerabilities found.

Build Info

Metric Value
Build time 42s
Go version go1.25.8
Commit 1b83171

History (3 previous)

Commit Updated Status Summary
27b40e8 2026-03-11 00:18 UTC 35.91 MB (+4.0 KB / +0.01%)
9cdf53a 2026-03-11 00:11 UTC 35.90 MB (0.0 KB / 0.00%)
727db83 2026-03-10 03:09 UTC 35.90 MB (0.0 KB / 0.00%)

🤖 Updated on each push.

…ients

- Add nil guard to DB.SetLogger to prevent panic on nil input
- Propagate logger to replica client via anonymous interface assertion
  so client logs inherit the store-scoped logger hierarchy
…pile-time checks

Replace hardcoded log attribute strings with constants in a new log.go
file and introduce a named LoggerSetter interface to replace anonymous
interface assertions. Add compile-time interface checks for all types
that implement SetLogger.
Move SetLogger into the ReplicaClient interface instead of using a
separate LoggerSetter interface with type assertions. This ensures all
implementations support logger propagation at compile time. Add no-op
SetLogger to mock and test clients to satisfy the interface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(logging): add .With() system identifiers to all top-level loggers

1 participant