puff / logger
Lightweight PSR-3 logger for Puff
Requires
- php: ^8.2
- psr/log: ^3.0
- puff/config: dev-main
- puff/di: dev-main
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2026-08-27 12:43:09 UTC
README
puff/logger is a PSR-3 logger with configurable output handlers and level filtering.
'logger' => [ 'handler' => Puff\Logger\Handler\StreamHandler::class, 'level' => Psr\Log\LogLevel::INFO, 'stream' => 'php://stderr', 'path' => dirname(__DIR__) . '/runtime/logs', ],
The default StreamHandler writes to php://stderr, which keeps command output on stdout clean and works with process supervisors and container log collectors. FileHandler remains available and writes daily files to logger.path. Custom handlers must implement Puff\Logger\Handler\HandlerInterface and are instantiated through the Puff container.
Application entry points can use the logger() helper, which returns the registered PSR-3 logger:
logger()->info('User logged in', ['user_id' => $userId]); logger()->error('Payment failed', ['exception' => $exception]);
The optional Log facade resolves the same PSR-3 logger from the container:
Log::info('User {id} logged in', ['id' => 42]); Log::error('Payment failed', ['exception' => $exception]);
Log is a global facade; the concrete implementation remains Puff\Logger\Logger.
Scalar PSR-3 placeholders are interpolated, while the complete context remains available as structured JSON:
logger()->info('User {id} logged in', ['id' => 42]);
Throwable context is normalized to its class, message, code, file, and line. Stack traces are intentionally omitted to keep production logs bounded.
Services should continue to receive Psr\Log\LoggerInterface through constructor injection. For repeated logging in a loop, resolve the helper once and reuse the returned logger.