-
-
Save grammaticof/3820701 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( $app['debug'] ) { | |
$logger = new Doctrine\DBAL\Logging\DebugStack(); | |
$app['db.config']->setSQLLogger($logger); | |
$app->error(function(\Exception $e, $code) use ($app, $logger) { | |
if ( $e instanceof PDOException and count($logger->queries) ) { | |
// We want to log the query as an ERROR for PDO exceptions! | |
$query = array_pop($logger->queries); | |
$app['monolog']->err($query['sql'], array( | |
'params' => $query['params'], | |
'types' => $query['types'] | |
)); | |
} | |
}); | |
$app->after(function(Request $request, Response $response) use ($app, $logger) { | |
// Log all queries as DEBUG. | |
foreach ( $logger->queries as $query ) { | |
$app['monolog']->debug($query['sql'], array( | |
'params' => $query['params'], | |
'types' => $query['types'] | |
)); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment