communitales / log
Communitales Log Component
Requires
- php: >=8.4
- psr/log: ^3.0
Requires (Dev)
- esi/phpunit-coverage-check: ^3.1
- friendsofphp/php-cs-fixer: ^v3.95
- monolog/monolog: ^3.11
- phpstan/phpstan: ^2.2
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^13.3
- rector/rector: ^2.6
- sentry/sentry: ^4.31
Suggests
- sentry/sentry: Enables automatic exception reporting to Sentry.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-06 08:45:58 UTC
README
A PSR-3 compatible logger decorator with convenient exception logging.
Setup
Wrap any PSR-3 logger in ExceptionLogger and inject the decorator through its interface:
use Communitales\Component\Log\ExceptionLogger; $exceptionLogger = new ExceptionLogger($psrLogger);
Symfony example:
services: Communitales\Component\Log\ExceptionLogger: arguments: $logger: '@logger' Communitales\Component\Log\ExceptionLoggerInterface: alias: Communitales\Component\Log\ExceptionLogger
Usage
The decorator implements Psr\Log\LoggerInterface, so it supports ordinary log messages as well as exceptions:
use Communitales\Component\Log\ExceptionLoggerInterface; use Psr\Log\LogLevel; use RuntimeException; final readonly class SomeService { public function __construct(private ExceptionLoggerInterface $logger) { } public function execute(): void { $this->logger->notice('Starting operation'); try { // Perform operation. } catch (RuntimeException $exception) { $this->logger->logException( $exception, LogLevel::ERROR, ['operation' => 'example'], ); } } }
The exception is passed to the underlying logger using the standard exception context key.
Sentry integration
If the optional sentry/sentry package is installed, ExceptionLogger also reports exceptions through Sentry\captureException(). Configure and initialize the Sentry SDK in the consuming application. No additional integration code is needed in this package.