phrity / monolog
Extensions for Monolog logger framework; Context normalizer, persister, interpolator.
Requires
- php: ^8.1
- monolog/monolog: ^3.0
- phrity/util-accessor: ^1.0
- psr/log: ^2.0 | ^3.0
- symfony/property-access: ^6.0 | ^7.0
- symfony/serializer: ^6.0 | ^7.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^10.0 | ^11.0 | ^12.0
- squizlabs/php_codesniffer: ^3.5
- symfony/uid: ^6.0 | ^7.0
This package is auto-updated.
Last update: 2025-04-17 08:59:44 UTC
README
Introduction
Extensions to Monolog logging framework. Adds additional Context related Processors.
Installation
Install with Composer;
composer require phrity/monolog
Processors
List of Monolog Processors included in this library.
ContextInterpolator
Advanced interpolator that attempts to interpolate context entity to string.
$logger->pushProcessor(new ContextInterpolator()); $logger->info('Test {stringable}', [ 'stringable' => new MyStringableClass(), ]);
Reference can also use .
to access properties in objects and arrays.
$logger->pushProcessor(new ContextInterpolator()); $logger->info('Test {myClass.myProperty}', [ 'myClass' => new Mylass(myProperty: 1234), ]);
Optionally the interpolator can use Symfony Serializer to normalize context data used for interpolation.
The DefaultSerializer
provides a standard normalization setup, but you can use any class that implements Symfony NormalizerInterface
.
$logger->pushProcessor(new ContextInterpolator(new DefaultSerializer())); $logger->info('Test {dateTime}', [ 'dateTime' => new DateTime(), ]);
ContextNormalizer
Wrapper for Symfony Serializer that normalize context data.
$logger->pushProcessor(new ContextNormalizer()); $logger->info('Test', [ 'dateTime' => new DateTime(), ]);
By default it uses DefaultSerializer
, a standard normalization setup, but you can use any class that implements Symfony NormalizerInterface
.
$logger->pushProcessor(new ContextInterpolator(new MyNormalizer())); $logger->info('Test', [ 'dateTime' => new DateTime(), ]);
ContextPersister
The Persister keeps context data that will be used on all log actions.
$logger->pushProcessor(new ContextPersister(['initial' => 'Will be added to all log actions'])); $logger->info('Test');
By keeping the reference of the Persister, persisted context can be changed at any point.
$persister = new ContextPersister(['initial' => 'Will be added to all log actions.']); $logger->pushProcessor($persister); $persister->add(['added' => 'Will be added to all subsequent log actions']); $logger->info('Test'); $persister->set(['replaced' => 'Will replace existing on subsequent log actions']); $logger->info('Test'); $persister->reset(); $logger->info('Test');
Versions
Version | PHP | |
---|---|---|
1.0 |
^8.1 |
phrity/monolog v1.0 |