https://github.com/tomphp/php-context-logger
A PSR-3 compliant logger decorator which allows context metadata to be built up.
https://github.com/tomphp/php-context-logger
logging php psr3
Last synced: 3 months ago
JSON representation
A PSR-3 compliant logger decorator which allows context metadata to be built up.
- Host: GitHub
- URL: https://github.com/tomphp/php-context-logger
- Owner: tomphp
- License: mit
- Created: 2016-11-20T19:12:52.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-24T11:32:46.000Z (over 9 years ago)
- Last Synced: 2025-07-27T02:46:56.417Z (9 months ago)
- Topics: logging, php, psr3
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Context Logger
[](https://travis-ci.org/tomphp/php-context-logger)
[](https://packagist.org/packages/tomphp/context-logger)
[](https://packagist.org/packages/tomphp/context-logger)
[](https://packagist.org/packages/tomphp/context-logger)
[](https://packagist.org/packages/tomphp/context-logger)
A PSR-3 compliant logger decorator which allows context metadata to be built up.
## Installation
```
$ composer require tomphp/context-logger
```
## Usage
```php
pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));
$log = new ContextLogger($monolog);
$log->addContext('correlation_id', uniqid());
$log->error('There was an error');
```
### Setting the Context
An original context can be set by providing an array as the second argument to
the constructor:
```php
$log = new ContextLogger($monolog, ['correlation_id' => uniqid()]);
```
The context can be added to or modified by the
`addContext(string $name, $value)` method.
The context can also be added to/modified by providing an array to the
`$context` parameter of any of the PSR-3 `LoggerInterface` methods.
### Removing Context
You can remove a item from the context by using the `removeContext(string $name)`
method.