We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Cannot instantiate abstract class Phalcon\Logger

Hi all , i want to log my mysql queries but i couldn do it , because when i want to use code on webiste

use Phalcon\Logger, Phalcon\Db\Adapter\Pdo\Mysql as Connection, Phalcon\Events\Manager as EventsManager, Phalcon\Logger\Adapter\File;

$di->set('db', function() {

$eventsManager = new EventsManager();

$logger = new Logger("app/logs/debug.log");

//Listen all the database events
$eventsManager->attach('db', function($event, $connection) use ($logger) {
    if ($event->getType() == 'beforeQuery') {
        $logger->log($connection->getSQLStatement(), Logger::INFO);
    }
});

$connection = new Connection(array(
    "host" => "localhost",
    "username" => "root",
    "password" => "secret",
    "dbname" => "invo"
));

//Assign the eventsManager to the db adapter instance
$connection->setEventsManager($eventsManager);

return $connection;

});

but when i run its , i got an error like that : Fatal error: Cannot instantiate abstract class Phalcon\Logger in /clvol/webdata/popsbuy.com/htdocs/public/index.php on line 192

@geass hi!

  1. Remove Phalcon\Logger;
  2. Use Phalcon\Logger\Adapter\File as FileLogger;
  3. $logger = new FileLogger("app/logs/debug.log");


39.3k

So so thanks @boston :)