https://github.com/andrew-kamenchuk/def-logger
single php class psr logger implementation
https://github.com/andrew-kamenchuk/def-logger
logger php psr-3 single-class
Last synced: 6 months ago
JSON representation
single php class psr logger implementation
- Host: GitHub
- URL: https://github.com/andrew-kamenchuk/def-logger
- Owner: andrew-kamenchuk
- Created: 2014-10-06T18:23:16.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-08-07T02:23:53.000Z (almost 10 years ago)
- Last Synced: 2024-04-05T07:03:15.512Z (about 2 years ago)
- Topics: logger, php, psr-3, single-class
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## def-logger
(*single class psr compatible php logger*)
[](https://travis-ci.org/andrew-kamenchuk/def-logger)
basic usage:
```php
use def\Logger\Logger;
$logger = new Logger('php-app'); // or Logger::getLogger('php-app');
```
Now you can set a callable writer to process log messages:
```php
$logger->setWriter('print_r');
// or
// will print_r every 10 records formatted with default formatter
$logger->setWriter('print_r', Logger::ALL, 10);
```
There are some writers already defined, for example:
```php
$logger->setStreamWriter(STDERR, Logger::DEBUG | Logger::INFO); // there are also error_log, syslog and mail writers
```
You can change default formatting:
```php
$logger->setDefaultFormatter(function ($levelname, $message, array $context) {
//
});
```
or pass custom formatter with writer:
```php
$logger->setWriter('print_r', Logger::ALL, 10, function ($levelname, $message, array $context) {
//
});
```
It is possible to disable some levels for handling:
```php
$logger->disable(Logger::DEBUG | Logger::INFO);
```
```addContextProcessor``` method allows add some extra data to context:
```php
$logger->addContextProcessor('some_key', function (array $context) {
return 'some_value';
});
```