feat(logging): add .With() system identifiers to all top-level loggers#1191
Open
feat(logging): add .With() system identifiers to all top-level loggers#1191
Conversation
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
PR Build Metrics✅ All clear — no issues detected
Binary Size
Dependency ChangesNo dependency changes. govulncheck OutputBuild Info
History (3 previous)
🤖 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Example log output:
level=INFO msg="compacted snapshots" system=store db=mydb.sqlite subsystem=compactorChanges by tier:
slog.Debug→db.Logger.Debuginverify()system=store, Server taggedsystem=serverDB.SetLogger()propagates store logger withdb=<name>to DB and compactor; called inNewStoreandRegisterDBsubsystem=compactor, WALReader getssubsystem=wal-readerSetLogger()for logger propagation via anonymous interface assertionMotivation 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.gochanges from PR #1179.Fixes #1189
How Has This Been Tested?
go build ./...— passesgo test ./...— all tests pass (including existing store/compactor/replica tests)go vet ./...— cleanTypes of changes
Checklist
go fmt,go vet)go test ./...)