Sql Logger in dev
This commit is contained in:
parent
9863ace419
commit
f3c067614a
@ -146,7 +146,14 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
||||
protected function _initDoctrine()
|
||||
{
|
||||
$c = new Zend_Config($this->getOptions());
|
||||
|
||||
$config = new \Doctrine\DBAL\Configuration();
|
||||
|
||||
if (APPLICATION_ENV == 'development') {
|
||||
$logger = new Scores_Logger_Sql();
|
||||
$config->setSQLLogger($logger);
|
||||
}
|
||||
|
||||
$connectionParams = array(
|
||||
'dbname' => $c->profil->db->metier->params->dbname,
|
||||
'user' => $c->profil->db->metier->params->username,
|
||||
|
46
library/Scores/Logger/Sql.php
Normal file
46
library/Scores/Logger/Sql.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
use Doctrine\DBAL\Logging\SQLLogger;
|
||||
|
||||
class Scores_Logger_Sql implements SQLLogger
|
||||
{
|
||||
/**
|
||||
* Executed SQL queries.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $query = array();
|
||||
|
||||
/**
|
||||
* If Debug Stack is enabled (log queries) or not.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $enabled = true;
|
||||
|
||||
/**
|
||||
* @var float|null
|
||||
*/
|
||||
public $start = null;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function startQuery($sql, array $params = null, array $types = null)
|
||||
{
|
||||
if ($this->enabled) {
|
||||
$this->start = microtime(true);
|
||||
$this->query = array('sql' => $sql, 'params' => $params, 'types' => $types, 'executionMS' => 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function stopQuery()
|
||||
{
|
||||
if ($this->enabled) {
|
||||
$this->query['executionMS'] = microtime(true) - $this->start;
|
||||
file_put_contents('logger.log', print_r($this->query,1), FILE_APPEND);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user