Implement log/slog framework for structured logging#18
Merged
massiveio merged 20 commits intoAug 28, 2025
Conversation
Co-authored-by: cloorc <13597105+cloorc@users.noreply.github.com>
Co-authored-by: cloorc <13597105+cloorc@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Need to use log/slog framework to print log information
Implement log/slog framework for structured logging
Aug 28, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR migrates from the standard log package to Go's structured logging framework log/slog introduced in Go 1.21, providing consistent structured logging throughout the codebase.
- Replaces
log.Printf(),log.Fatalf(), andfmt.Printf()error logging calls withslog.Error() - Converts fatal logging patterns to use
slog.Error()followed byos.Exit(1) - Adds
log/slogandosimports across all affected files
Reviewed Changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 20 comments.
Show a summary per file
| File | Description |
|---|---|
| api.go | Updates auto-save error logging in core library |
| cmd/debug_matching/main.go | Migrates command-line debug tool to structured logging |
| cmd/target_performance/main.go | Updates performance testing tool error logging |
| cmd/performance_benchmark/main.go | Converts benchmark tool logging |
| example/main.go | Updates main example application logging |
| example/clustered/main.go | Migrates clustered example to structured logging |
| example/forest_demo/main.go | Updates forest demo logging patterns |
| example/brokers_demo/main.go | Converts broker demo error handling |
| example/dimension_consistency/main.go | Updates dimension demo logging |
| example/multitenant_demo/main.go | Migrates multitenant demo logging |
| example/weight_conflict_demo/main.go | Updates weight conflict demo error handling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Cloorc <13597105+cloorc@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Cloorc <13597105+cloorc@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Cloorc <13597105+cloorc@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Cloorc <13597105+cloorc@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Cloorc <13597105+cloorc@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mass <wittcnezh@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mass <wittcnezh@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mass <wittcnezh@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mass <wittcnezh@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mass <wittcnezh@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mass <wittcnezh@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mass <wittcnezh@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mass <wittcnezh@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mass <wittcnezh@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mass <wittcnezh@outlook.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Mass <wittcnezh@outlook.com>
Signed-off-by: Cloorc <wittcnezh@foxmail.com>
massiveio
approved these changes
Aug 28, 2025
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.
This PR replaces the standard
logpackage andfmt.Printferror logging with Go's modernlog/slogframework to provide structured logging throughout the codebase.Changes Made
Core Library
AutoSavefunction to useslog.Error()instead offmt.Printf()for error logginglog/slogimport to enable structured logging in the core APICommand-Line Tools
Updated all command-line tools in
cmd/to use structured logging:cmd/debug_matching/main.gocmd/target_performance/main.gocmd/performance_benchmark/main.goExample Applications
Updated all example applications in
example/to use structured logging:example/main.goexample/clustered/main.goexample/forest_demo/main.goexample/brokers_demo/main.goexample/dimension_consistency/main.goexample/multitenant_demo/main.goexample/weight_conflict_demo/main.goLogging Format Changes
Before:
After:
Benefits
Example Output
The new structured logging provides clearer error messages:
This maintains backward compatibility while providing better structured logging for improved observability and debugging capabilities.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.