Skip to content

[ISSUE #1306] [Go] Support custom logger injection - #1356

Open
gagraler wants to merge 1 commit into
apache:masterfrom
gagraler:issue-1306-go-custom-logger
Open

gagraler wants to merge 1 commit into
apache:masterfrom
gagraler:issue-1306-go-custom-logger

Conversation

@gagraler

@gagraler gagraler commented Sep 2, 2026

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Fixes #1306

Brief Description

  • Add a framework-neutral Logger interface and global SetLogger API.
  • Keep the existing Zap-backed logger as the default and preserve caller attribution and lazy formatted logging.
  • Make newly created producers and consumers inherit the configured logger and their client_id context.
  • Add a documented log/slog JSON adapter example.
  • Correct invalid logging format directives exposed by the new adapter.

How Did You Test This Change?

  • go build
  • go test -v
  • go test ./...
  • go test -race -run TestSetLoggerIsUsedByNewClients -count=1
  • git diff --check

Note: go vet ./... continues to report the existing context.WithTimeout cancel warnings in client_manager.go and conn.go; those warnings are present on the base commit and are outside this change.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

This PR adds a clean logger abstraction layer to the Go client, enabling applications to inject their own logging framework. The implementation is well-structured and the format string fixes address real bugs.

Review

Correctness

  • The Logger interface is minimal and idiomatic Go.
  • Format string fixes are correct: %w%v (since %w is only valid in fmt.Errorf), {}%s/%d/%v (Go uses printf-style, not brace-style), %d%s for string clientID.
  • The internalLogger adapter correctly bridges the public interface to internal call sites.

Compatibility

  • SetLogger/ResetLogger are additive; existing code continues to work with the default Zap logger.
  • No breaking changes to public APIs.

Tests

  • Good coverage with a recording logger that verifies delegation.
  • Race condition test included.

Documentation

  • README addition with a complete log/slog adapter example is helpful.

One minor note: SetLogger panics on nil input. This is acceptable Go idiom (fail-fast), but a doc comment clarification like "Panics if logger is nil" could be added for discoverability.

LGTM.


Automated review by github-manager-bot

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Adds custom logger injection support to the Go client. Well-structured feature addition with clean API design.

Key changes reviewed:

  • Framework-neutral Logger interface with Debug/Info/Warn/Error/With methods
  • Global SetLogger/ResetLogger API for application-level logger configuration
  • Existing Zap-backed logger preserved as default via internalLogger wrapper
  • Producers and consumers inherit the configured logger and client_id context
  • Fixes invalid %w format directives in log calls (Zap's Errorf uses %v, not %w)
  • Documented log/slog JSON adapter example in README
  • Thread-safe SetLogger with mutex protection for concurrent access

Minor observations:

  • The SetLogger call inside InitLogger() creates a slight recursion risk if SetLogger were to call InitLogger — but the current implementation is safe (no circular call)
  • Test coverage includes TestSetLoggerIsUsedByNewClients with race detection

LGTM 👍


Automated review by github-manager-bot

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

This PR adds a framework-neutral Logger interface and SetLogger API, allowing applications to route RocketMQ logs through their existing logging framework. The implementation is well-designed:

Strengths:

  • Clean public interface (Logger) with minimal surface area (Debug/Info/Warn/Error/With)
  • internalLogger wrapper preserves backward compatibility with formatted methods (Debugf, Infof, etc.)
  • Correctly fixes invalid %w format directives → %v (since %w is only valid in fmt.Errorf)
  • Good documentation with log/slog adapter example in README
  • Tests included for the new logger functionality
  • SetLogger panics on nil input (fail-fast)

Minor observations:

  • The fatalLogger interface is defined but not used in the visible diff — consider documenting its intended use or removing if unused
  • ResetLogger comment could mention that it also restores environment variable configuration

Overall, this is a solid enhancement that improves the client's integration with application logging frameworks. LGTM.


Automated review by github-manager-bot

@RockteMQ-AI

Copy link
Copy Markdown

⚠️ Merge conflict detected

This PR has conflicts with the base branch and cannot be merged. Please rebase or merge the base branch into your branch and resolve the conflicts:

git fetch origin
git checkout issue-1306-go-custom-logger
git rebase origin/master
# resolve conflicts, then:
git push --force-with-lease

This is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved.


Automated notification by github-manager-bot

Introduce a framework-neutral Logger interface and SetLogger API while preserving the existing Zap-backed default. Add producer and consumer inheritance coverage, JSON slog documentation, and correct invalid log format directives exposed by the adapter.
@gagraler
gagraler force-pushed the issue-1306-go-custom-logger branch from 21a03ce to f97284a Compare September 16, 2026 14:01
@RockteMQ-AI

Copy link
Copy Markdown

⚠️ Scope expansion detected

This PR was originally titled [ISSUE #1306] [Go] Support custom logger injection and was previously approved for that scope. Since the last review, 9 new commits have been added that expand the PR to include:

  • C#: LiteSimpleConsumer implementation (~2,500+ lines), ClientManager refactoring, Session changes
  • Python: LiteSimpleConsumer, route manager refactoring, client manager changes
  • Node.js: Multiple client changes
  • Go: Client manager refactoring beyond the original logger injection

The PR title and description no longer match the actual changes. This makes it difficult for reviewers to understand the full scope and for maintainers to evaluate the change holistically.

Recommendation: Please consider splitting this into separate, focused PRs:

  1. One PR for the Go custom logger injection (original scope — already approved)
  2. Separate PRs for each language's LiteSimpleConsumer / other changes

This helps reviewers focus on one concern at a time and makes the git history clearer.


Automated review by github-manager

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Reviewed 14 changed file(s) in this PR.

Findings

  • Critical: 0
  • Warning: 0
  • Info: 1

Please review the inline comments for specific suggestions.


Automated review by github-manager-bot

Comment thread golang/logger_test.go

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Re-reviewed after new commits. The custom logger injection feature for the Go client is well-implemented:

  • Clean Logger interface with Debug/Info/Warn/Error/With methods
  • SetLogger/ResetLogger API for application-level logger injection
  • internalLogger wrapper preserves format-string compatibility
  • Format string fixes: %w changed to %v for Errorf calls — correct since %w is only valid in fmt.Errorf, not in SugaredLogger.Errorf
  • README documentation with a concrete slog adapter example
  • Thread-safe by design via interface contract

LGTM.


Automated review by github-manager-bot

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.

[Enhancement] Support injecting a custom logger for structured JSON logging

2 participants