phapi / log
Phapi Log contains a Di container validator
Installs: 1 541
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=5.6.0
- phapi/contract: 1.*
- psr/log: 1.*
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- mockery/mockery: 0.9.*
- phpunit/phpunit: 4.*
Suggests
- monolog/monolog: 1.*
This package is not auto-updated.
Last update: 2021-02-05 22:35:07 UTC
README
Package contains a Di Container Validator for validating loggers.
Configuration
Loggers must be PSR-3 compatible. If no logger is configured or if the configured logger doesn't comply with PSR-3 then the NullLogger
that is supplied in the PSR-3 package will be used.
In this example we will configure and use Monolog and set up a simple logger that logs to a file.
First, add the needed dependency to composer.json:
$ composer require monolog/monolog:1.*
After that it's just a matter of updating the configuration:
<?php use Monolog\Logger; use Monolog\Handler\StreamHandler; $container['log'] = function ($container) { $log = new Logger('default'); // IMPORTANT! Make sure you use an absolute path. Relative paths aren't guaranteed to // work in cases where errors and exceptions occur. $log->pushHandler(new StreamHandler(__DIR__ . '/../logs/logfile.log', Logger::WARNING)); return $log; };
Usage
<?php // add records to the log $container['log']->warning('Foo'); $container['log']->error('Bar');
License
Phapi Log is licensed under the MIT License - see the license.md file for details
Contribute
Contribution, bug fixes etc are always welcome.