feat: add PSR-3 Trap logger with STDERR fallback#212
Open
petrdobr wants to merge 2 commits intobuggregator:masterfrom
Open
feat: add PSR-3 Trap logger with STDERR fallback#212petrdobr wants to merge 2 commits intobuggregator:masterfrom
petrdobr wants to merge 2 commits intobuggregator:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a standalone client-side PSR-3 logger implementation for Trap, exposed via TrapHandle::logger() (and therefore callable as trap()::logger()), with TCP delivery using a Monolog-style JSON payload and a STDERR fallback.
Changes:
- Introduced
Buggregator\Trap\Log\TrapLogger(PSR-3AbstractLogger) with sync + fiber-aware “async” transport and STDERR fallback formatting. - Added
TrapHandle::logger()singleton accessor configured byTRAP_MONOLOG_HOST/TRAP_MONOLOG_PORT. - Added unit tests for logger access, fallback formatting, and invalid level handling; added
psr/logdependency.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/Log/TrapLogger.php |
New PSR-3 logger that attempts TCP delivery (sync/async) and falls back to STDERR text lines. |
src/Client/TrapHandle.php |
Adds logger() accessor and env-based configuration; refactors env getter to static. |
tests/Unit/Client/TrapLoggerTest.php |
Adds tests for logger singleton, fallback formatting, and invalid level behavior. |
composer.json |
Adds psr/log requirement for PSR-3 interfaces/base logger. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
What was changed
trap()::logger()TrapLoggerbased onpsr/logSTDERRoutput when Trap server delivery failsTRAP_MONOLOG_HOSTandTRAP_MONOLOG_PORTWhy?
The issue asks for a standalone PSR-3 logger implementation for the client side of the project, accessible via
trap()::logger().This makes Trap usable in places where a PSR-3 logger is expected without requiring Monolog as the application logger. The logger tries to send records to the Trap server first, and falls back to
STDERRin text format when delivery is not possible.The async/fiber path is implemented as best-effort non-blocking behavior to avoid interfering with fiber-based execution.
Checklist
Notes
The fiber/async path is implemented as best-effort non-blocking behavior.
I’m open to adjusting it if a different async strategy is preferred.