Package contains a Di Container Validator for validating loggers.
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;
};
<?php
// add records to the log
$container['log']->warning('Foo');
$container['log']->error('Bar');
Phapi Log is licensed under the MIT License - see the license.md file for details
Contribution, bug fixes etc are always welcome.