I have tried to implement Monolog based on an example
My code, in a simple way, looks like
use \Psr\Http\Message\ServerRequestInterface;
use \Psr\Http\Message\ResponseInterface;
require '../vendor/autoload.php';
$c = new \Slim\Container($configuration);
$app = new \Slim\App($c);
/* Logger */
$container = $app->getContainer();
$container['logger'] = function($c) {
$logger = new \Monolog\Logger('API_logger');
$file_handler = new \Monolog\Handler\StreamHandler("../logs/API.log");
$logger->pushHandler($file_handler);
return $logger;
} ;
/** my routes here **/
$app->run();
but then when I try to execute Monolog and save to log via
$this->logger->addInfo("Something interesting happened");
in my route function it throws an error Using $this when not in object context
Any clue why the code from an example is not working as expected?