docs: Update example code, add log initialization configurations#1449
Merged
crossoverJie merged 1 commit intoapache:masterfrom Dec 22, 2025
Merged
docs: Update example code, add log initialization configurations#1449crossoverJie merged 1 commit intoapache:masterfrom
crossoverJie merged 1 commit intoapache:masterfrom
Conversation
09b8f0e to
db93d24
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates example files to use Go's standard log/slog package (introduced in Go 1.21) for structured logging, replacing the previous basic logging approach. It adds comprehensive logging configuration with file output and rotation capabilities via the lumberjack library to improve the out-of-the-box experience for users.
Key Changes:
- Adds
gopkg.in/natefinch/lumberjack.v2dependency for log rotation support - Updates all four example files (producer, consumer, reader, consumer-listener) with complete slog logger initialization
- Replaces
log.Fatal()andfmt.Printf()calls with structuredlogger.Error()andlogger.Info()calls
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| go.mod | Adds lumberjack.v2 dependency for log rotation functionality |
| go.sum | Adds checksums for lumberjack.v2 dependency |
| examples/reader/reader.go | Implements slog logger with file rotation and updates all logging calls to use structured logging |
| examples/producer/producer.go | Implements slog logger with file rotation and updates all logging calls to use structured logging |
| examples/consumer/consumer.go | Implements slog logger with file rotation and updates all logging calls to use structured logging |
| examples/consumer-listener/consumer-listener.go | Implements slog logger with file rotation and updates all logging calls to use structured logging |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9e0e22f to
95679a7
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
95679a7 to
8af6732
Compare
crossoverJie
approved these changes
Dec 17, 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.
Master Issue: #1234
Motivation
The
log/slogpackage, introduced in Go 1.21 has become the standard library for structured logging, which provides support for redirecting logs to files and enabling log rotation.Additionally, since pulsar default logger uses
log.NewLoggerWithLogrus(logrus.StandardLogger()), logs cannot be output to the files when users haven't set up logrus explicit configuration. Therefore, maybe we should useslogand give a complete log settings in our examples to enhance the out-of-the-box experience for users.Modifications
Add log initialization configurations in example files.
Verifying this change
This change is a trivial rework without any test coverage.
Does this pull request potentially affect one of the following parts:
If
yeswas chosen, please highlight the changesDocumentation