Skip to content

fix: add RenderMessage() method for custom sinks (#64)#65

Merged
willibrandon merged 4 commits intomainfrom
feature/logevent-render-message
Oct 4, 2025
Merged

fix: add RenderMessage() method for custom sinks (#64)#65
willibrandon merged 4 commits intomainfrom
feature/logevent-render-message

Conversation

@willibrandon
Copy link
Owner

Description

Adds a public RenderMessage() method to core.LogEvent to 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.go to resolve an import cycle by using interface-based design.

Type of change

  • Bug fix
  • New feature
  • Performance improvement
  • Documentation update

Checklist

  • Tests pass (go test ./...)
  • Linter passes (golangci-lint run)
  • Benchmarks checked (if performance-related)
  • Documentation updated (if needed)
  • Zero-allocation promise maintained (if applicable)

Additional notes

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
@willibrandon willibrandon self-assigned this Oct 4, 2025
@willibrandon willibrandon added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request sinks Changes to log event sinks (output destinations) labels Oct 4, 2025
@willibrandon willibrandon requested a review from Copilot October 4, 2025 09:36
Copy link

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

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 to core.LogEvent with proper error handling and fallback
  • Refactored token parser to use fmt.Stringer interface 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}")
@willibrandon willibrandon merged commit ca29c46 into main Oct 4, 2025
26 checks passed
@willibrandon willibrandon deleted the feature/logevent-render-message branch October 4, 2025 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request sinks Changes to log event sinks (output destinations)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom sinks cannot render message templates - internal/parser is not accessible

1 participant