psr/log
PSR-3 logging interfaces for PHP. Provides LoggerInterface, traits, and related classes to standardize how libraries accept and emit log messages. Not a logger implementation—use it to type-hint a logger or build your own PSR-3 compliant logger.
Start by installing the package via Composer: composer require psr/log. This gives you access to the Psr\Log\LoggerInterface and supporting classes like AbstractLogger, LoggerAwareTrait, and TestLogger. Your first step is to inject LoggerInterface into classes that need logging — typically via constructor injection. Use the TestLogger for unit tests to assert log messages without writing to disk. Remember: this package only provides the interface, not a concrete logger — you’ll pair it with a full logging library like Monolog, Symfony’s Logger, or Laravel’s built-in logger (which already adheres to PSR-3).
LoggerInterface in constructors or methods. Laravel automatically resolves the logger service (which implements PSR-3) when you type-hint it, so no extra config is needed.$logger?->info('...') (PHP 8.0+) or if ($logger) { $logger->info(...) } for graceful fallbacks.Log facade and Psr\LoggerInterface are fully compatible. You can inject LoggerInterface directly into jobs, mailables, middleware, or service classes and leverage Laravel’s stackable, channel-based configuration (e.g., stack, daily, single) without changes.Psr\Log\Test\TestLogger in tests to capture and inspect log entries:
$logger = new TestLogger;
$service = new MyService($logger);
$service->doSomething();
$this->assertTrue($logger->hasInfoThatContains('Doing work'));
monolog/monolog).array|mixed[]: Avoid passing non-array values to context (e.g., objects or scalars); use ['error' => (string) $e] or ['data' => json_encode($data)]. PSR-3 requires context to be an array of scalar or array values.info()) return void (since v2.0+). Don’t chain or assign results.array|mixed[]). Ensure your project supports this.mixed[] in context help static analyzers; avoid mixed $context outside interface compliance.LoggerAwareInterface + use LoggerAwareTrait in your classes to auto-inject the logger from Laravel’s container — but prefer constructor injection for clarity and testability in modern apps.How can I help you explore Laravel packages today?