-
Notifications
You must be signed in to change notification settings - Fork 49
feat(logger): Implement custom logger injection for Typesense client #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| $this->assertNotNull($config->getNearestNode()); | ||
| } | ||
| } | ||
|
|
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an extra blank line at the end of the file. PSR-12 requires exactly one blank line at the end of files. Remove the extra blank line on line 195.
| <?php | ||
|
|
||
| include '../vendor/autoload.php'; |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other example files (alias_operations.php, cluster_operations.php, collection_operations.php, info_operations.php), consider adding the PHPStorm suppression annotation at the top of the file after the opening PHP tag: /** @noinspection ForgottenDebugOutputInspection */. This suppresses IDE warnings about debug output functions like print_r and echo in example files.
|
|
||
| $logger = $config->getLogger(); | ||
|
|
||
| // Should fall back to default logger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could there be a warning log right after the default's instantiation in cases where the instance of the logger doesn't satisfy the interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be even more strict and just throw here an exception - it is clearly a configuration issue (like wrong autowiring in symfony).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not :)
|
@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 |
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