feat(logger): Implement custom logger injection for Typesense client#113
feat(logger): Implement custom logger injection for Typesense client#113jkobus wants to merge 3 commits intotypesense:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements custom logger injection support for the Typesense PHP client, allowing users to provide their own PSR-3 compatible logger instead of relying on the default Monolog logger. This enhancement improves flexibility for users who want to integrate Typesense logging with their existing logging infrastructure.
Changes:
- Modified
Configurationclass to accept and validate custom PSR-3 logger instances via theloggerconfiguration option - Added comprehensive test coverage for logger injection scenarios including custom loggers, log levels, and edge cases
- Provided a working example demonstrating both custom logger usage and default logger configuration
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Lib/Configuration.php | Implements custom logger injection with PSR-3 interface validation, falling back to default Monolog logger when no custom logger is provided |
| tests/Feature/ConfigurationTest.php | Comprehensive test suite covering default logger, custom logger, custom log levels, mock loggers, invalid logger handling, and configuration validation |
| examples/custom_logger.php | Example demonstrating custom logger injection and default logger configuration patterns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@jkobus thank you for the PR! Was the Copilot review requested by you, or did this happen without your consent? |
I think I accidentally brought mine here :-) |
No worries if that was the case, I just feel like AI reviews tend to bring visual noise with them and didn't want them start reviewing every PR out of nowhere haha |
|
Added |
Change Summary
The Typesense PHP client now supports injecting your own PSR-3 compatible logger instance instead of using the default Monolog logger.
Usage
With Custom Logger
You can pass any PSR-3 compatible logger instance via the
loggerconfiguration option:Compatible Loggers
Any PSR-3 compliant logger will work:
Default Behavior
If you don't provide a custom logger, the client will create a default Monolog logger that writes to stdout:
Implementation Details
The change was made in
src/Lib/Configuration.php:This ensures backward compatibility - existing code will continue to work without any changes.
Example
See
examples/custom_logger.phpfor a complete working example.PR Checklist