Skip to content

Implement log/slog framework for structured logging#18

Merged
massiveio merged 20 commits into
masterfrom
copilot/fix-08cebe36-2fac-4081-94e3-e7a29b263407
Aug 28, 2025
Merged

Implement log/slog framework for structured logging#18
massiveio merged 20 commits into
masterfrom
copilot/fix-08cebe36-2fac-4081-94e3-e7a29b263407

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 28, 2025

This PR replaces the standard log package and fmt.Printf error logging with Go's modern log/slog framework to provide structured logging throughout the codebase.

Changes Made

Core Library

  • api.go: Updated the AutoSave function to use slog.Error() instead of fmt.Printf() for error logging
  • Added log/slog import to enable structured logging in the core API

Command-Line Tools

Updated all command-line tools in cmd/ to use structured logging:

  • cmd/debug_matching/main.go
  • cmd/target_performance/main.go
  • cmd/performance_benchmark/main.go

Example Applications

Updated all example applications in example/ to use structured logging:

  • example/main.go
  • example/clustered/main.go
  • example/forest_demo/main.go
  • example/brokers_demo/main.go
  • example/dimension_consistency/main.go
  • example/multitenant_demo/main.go
  • example/weight_conflict_demo/main.go

Logging Format Changes

Before:

log.Printf("Failed to add rule: %v", err)
fmt.Printf("Auto-save error: %v\n", err)
log.Fatalf("Failed to create matcher: %v", err)

After:

slog.Error("Failed to add rule", "error", err)
slog.Error("Auto-save error", "error", err)
slog.Error("Failed to create matcher", "error", err)
os.Exit(1)

Benefits

  1. Structured Logging: Key-value pairs make logs easier to parse and query
  2. Modern Standard: Uses Go 1.21+'s official structured logging framework
  3. Better Observability: Consistent format improves monitoring and debugging
  4. No Breaking Changes: All existing functionality preserved

Example Output

The new structured logging provides clearer error messages:

2025/08/28 01:23:53 ERROR Failed to add rule error="weight conflict: rule already exists"

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.

Copilot AI and others added 2 commits August 28, 2025 01:24
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
Copilot AI requested a review from cloorc August 28, 2025 01:26
@cloorc cloorc marked this pull request as ready for review August 28, 2025 01:28
Copilot AI review requested due to automatic review settings August 28, 2025 01:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(), and fmt.Printf() error logging calls with slog.Error()
  • Converts fatal logging patterns to use slog.Error() followed by os.Exit(1)
  • Adds log/slog and os imports 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.

Comment thread example/multitenant_demo/main.go Outdated
Comment thread example/dimension_consistency/main.go Outdated
Comment thread example/forest_demo/main.go Outdated
Comment thread example/forest_demo/main.go Outdated
Comment thread example/weight_conflict_demo/main.go Outdated
Comment thread example/brokers_demo/main.go Outdated
Comment thread example/brokers_demo/main.go Outdated
Comment thread example/brokers_demo/main.go Outdated
Comment thread example/brokers_demo/main.go Outdated
Comment thread example/brokers_demo/main.go Outdated
cloorc and others added 17 commits August 28, 2025 14:42
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 massiveio merged commit 0f2bf7e into master Aug 28, 2025
2 checks passed
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.

4 participants