My app logs queries just fine when I use the standard way of query logging:
$di->setShared('db', function() use ($config){
$connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->name
));
$eventsManager = new \Phalcon\Events\Manager();
$logger = new \Phalcon\Logger\Adapter\File($config->application->logsDir . 'sql.log');
$eventsManager->attach('db', function($event, $connection) use ($logger){
if($event->getType() == 'beforeQuery'){
$logger->log($connection->getRealSQLStatement());
}
});
$connection->setEventsManager($eventsManager);
return $connection;
});
However, when i rename the service:
$di->setShared('another_db', function() use ($config){
$connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->name
));
$eventsManager = new \Phalcon\Events\Manager();
$logger = new \Phalcon\Logger\Adapter\File($config->application->logsDir . 'sql.log');
$eventsManager->attach('another_db', function($event, $connection) use ($logger){
if($event->getType() == 'beforeQuery'){
$logger->log($connection->getRealSQLStatement());
}
});
$connection->setEventsManager($eventsManager);
return $connection;
});
It does not log sql statements.
Do I need to do something else to get logging to work? I use this in my models to attach to the service:
$this->setConnectionService('another_db');
Thanks.