Skip to content

feat: add PSR-3 Trap logger with STDERR fallback#212

Open
petrdobr wants to merge 2 commits intobuggregator:masterfrom
petrdobr:feature/psr3-trap-logger
Open

feat: add PSR-3 Trap logger with STDERR fallback#212
petrdobr wants to merge 2 commits intobuggregator:masterfrom
petrdobr:feature/psr3-trap-logger

Conversation

@petrdobr
Copy link
Copy Markdown

What was changed

  • Added a standalone PSR-3 logger entrypoint via trap()::logger()
  • Introduced TrapLogger based on psr/log
  • Implemented log delivery to the Trap Monolog TCP port using Monolog-compatible JSON payloads
  • Added graceful fallback to plain-text STDERR output when Trap server delivery fails
  • Added support for both sync execution and fiber-aware async execution
  • Added environment-based configuration for logger transport via TRAP_MONOLOG_HOST and TRAP_MONOLOG_PORT
  • Added unit tests for logger access, invalid level handling, and fallback formatting

Why?

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 STDERR in 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.

Copy link
Copy Markdown

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 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-3 AbstractLogger) with sync + fiber-aware “async” transport and STDERR fallback formatting.
  • Added TrapHandle::logger() singleton accessor configured by TRAP_MONOLOG_HOST / TRAP_MONOLOG_PORT.
  • Added unit tests for logger access, fallback formatting, and invalid level handling; added psr/log dependency.

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.

Comment thread src/Log/TrapLogger.php
Comment thread tests/Unit/Client/TrapLoggerTest.php Outdated
Comment thread tests/Unit/Client/TrapLoggerTest.php Outdated
Comment thread src/Client/TrapHandle.php
Comment thread src/Log/TrapLogger.php Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add lightweight PSR-3 implementation

2 participants