fix: add RenderMessage() method for custom sinks (#64)#65
Merged
willibrandon merged 4 commits intomainfrom Oct 4, 2025
Merged
Conversation
Provides public API for rendering message templates in custom sinks. Handles destructuring operators (@), scalar hints ($), and format specifiers that were previously inaccessible to custom implementations. - Add RenderMessage() method to core.LogEvent - Refactor parser/token.go to break import cycle - Add tests and example
There was a problem hiding this comment.
Pull Request Overview
Adds a public RenderMessage() method to core.LogEvent to allow custom sinks to properly render message templates, fixing issue #64 where custom sinks failed with advanced template features.
- Added
RenderMessage()method tocore.LogEventwith proper error handling and fallback - Refactored token parser to use
fmt.Stringerinterface instead of concrete types to resolve import cycle - Created comprehensive example demonstrating custom sink usage with all template features
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| core/event.go | Added public RenderMessage() method with documentation and error handling |
| internal/parser/token.go | Refactored to use fmt.Stringer interface and removed import dependency |
| core/event_test.go | Added comprehensive tests for all template rendering features |
| examples/custom-sink/main.go | Created working example demonstrating custom sink with RenderMessage() |
| README.md | Updated custom sink documentation with new RenderMessage() usage |
| CHANGELOG.md | Documented the new feature and its capabilities |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Use reflection to identify capture.Null type instead of string comparison
- Clarify comment about time.Time custom formatting vs String() method
- Fix property detection in custom sink to check complete placeholder patterns (prevents false positives like "User" matching "{UserId}")
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.
Description
Adds a public
RenderMessage()method tocore.LogEventto allow custom sinks to properly render message templates. This fixes issue #64 where custom sinks had to use manual string replacement that failed with destructuring operators ({@Property}), scalar hints ({$Property}), and format specifiers ({Property:format}).The implementation follows Serilog's approach by providing a public API that handles all template rendering features. Also includes a refactor of
internal/parser/token.goto resolve an import cycle by using interface-based design.Type of change
Checklist
go test ./...)golangci-lint run)Additional notes
core/event_test.goexamples/custom-sink/main.gofmt.Stringerinterface instead of concrete types to break import cycle