-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add structured logging with slog
#19203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Adds support for structured logging with `slog`. To enable, pass
`--log-level json|logfmt` and optionally a `--log-level
debug|info|warn|error` (default info). `glog` is still the default
unless `slog` is explicitly enabled with the flags.
We still use a global logging package `go/vt/log` to make the migration
easier. In the future, each component should be passed in a logger.
The global functions in the log package now check if structured logging
is enabled. If so, passes the message to `slog`. If not, passes it to
`glog` as normal.
Call sites were migrated as so:
- `Info(...)` => `Info(fmt.Sprint(...))`
- `Infof(...)` => `Info(fmt.Sprintf(...))`
- ...and so on for other levels and `Depth` variants.
Example output:
```console
$ ./bin/vttablet
{"time":"2026-01-22T16:13:49.136782-05:00","level":"INFO","source":{"function":"vitess.io/vitess/go/vt/servenv.Init","file":"vitess.io/vitess/go/vt/servenv/servenv_unix.go","line":58},"msg":"Version: 24.0.0-SNAPSHOT (Git revision bba5510 branch 'structured-logging-slog') built on Thu Jan 22 15:59:46 EST 2026 by [email protected] using go1.25.6 darwin/arm64"}
{"time":"2026-01-22T16:13:49.136913-05:00","level":"ERROR","source":{"function":"vitess.io/vitess/go/vt/topo.Open","file":"vitess.io/vitess/go/vt/topo/server.go","line":261},"msg":"topo-global-server-address must be configured"}
```
Signed-off-by: Mohamed Hamza <[email protected]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
|
Hello! 👋 This Pull Request is now handled by arewefastyet. The current HEAD and future commits will be benchmarked. You can find the performance comparison on the arewefastyet website. |
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #19203 +/- ##
==========================================
- Coverage 69.88% 69.84% -0.04%
==========================================
Files 1611 1613 +2
Lines 215944 216158 +214
==========================================
+ Hits 150919 150985 +66
- Misses 65025 65173 +148 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Mohamed Hamza <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Mohamed Hamza <[email protected]> Co-authored-by: Tim Vaillancourt <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Description
Adds support for JSON structured logging with
slog. To enable, pass--log-structuredand optionally a--log-level debug|info|warn|error(default info).glogis still the default unlessslogis explicitly enabled with the flags.We still use a global logging package
go/vt/logto make the migration easier. In the future, each component should be passed in a logger.The global functions in the log package now check if structured logging is enabled. If so, passes the message to
slog. If not, passes it toglogas normal.Call sites were migrated using ast-grep as so:
Info(...)=>Info(fmt.Sprint(...))Infof(...)=>Info(fmt.Sprintf(...))Depthvariants.Call sites are now free to incrementally add additional attributes to the message.
Example JSON output:
Benchmark quick links:
Related Issue(s)
Checklist
Deployment Notes
AI Disclosure