mj-zana / logging
PSR-3 logging with channels, handlers, formatters and processors for Zana applications
v2.1.0
2026-10-25 20:32 UTC
Requires
- php: ^8.5
- mj-zana/core: ^2.0
- psr/log: ^3.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-25 20:42:55 UTC
README
A PSR-3 logger with named channels, handlers, formatters and processors. Requires PHP 8.5 or later.
composer require mj-zana/logging
Usage
Register LoggingServiceProvider and configure channels in config/logging.php:
return [ 'default' => 'app', 'channels' => [ 'app' => ['handler' => 'stream', 'path' => 'var/log/app.log', 'level' => 'info', 'formatter' => 'json'], 'audit' => ['handler' => 'stream', 'path' => 'var/log/audit.log'], 'test' => ['handler' => 'array'], ], ];
public function __construct(private LoggerInterface $logger) {} $this->logger->info('BMI {bmi} recorded for {patient}', ['bmi' => 22.5, 'patient' => $id]); $manager->channel('audit')->notice('Patient record exported');
- Handlers:
stream(a file, created with its directory, orphp://stderr),array(keeps records for tests) andnull. - Formatters:
lineandjson. Exceptions, dates, objects and resources in the context are normalized. - Without configuration: the default channel logs warnings and above to
php://stderr.
LogContext values (for example the correlation id that mj-zana/http sets for
each request) are added to every record's extra.
License
MIT — see LICENSE.