Monolog In Your Application
If you’re not already familiar with Monolog, it’s an excellent logging framework for PHP applications, which is why I’m going to use it here. First of all, get the Monolog library installed via Composer
php composer.phar require monolog/monolog
The dependency is named logger and the code to add it looks like this:
$container['logger'] = function($c) {
$logger = new \Monolog\Logger('my_logger');
$file_handler = new \Monolog\Handler\StreamHandler("../logs/app.log");
$logger->pushHandler($file_handler);
return $logger;
};
With the logger in place, I can use it from inside my route code with a line like this:
$this->logger->addInfo("Something interesting happened");