|
@@ -12,6 +12,8 @@ use Symfony\Component\Yaml\Yaml;
|
|
|
*/
|
|
|
class DoctrineMongoDBLogger
|
|
|
{
|
|
|
+ const LOG_PREFIX = 'MongoDB query: ';
|
|
|
+
|
|
|
protected $logger;
|
|
|
protected $nbQueries;
|
|
|
|
|
@@ -26,7 +28,7 @@ class DoctrineMongoDBLogger
|
|
|
++$this->nbQueries;
|
|
|
|
|
|
if (null !== $this->logger) {
|
|
|
- $this->logger->info(static::formatQuery($query));
|
|
|
+ $this->logger->info(static::LOG_PREFIX.static::formatQuery($query));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -35,6 +37,26 @@ class DoctrineMongoDBLogger
|
|
|
return $this->nbQueries;
|
|
|
}
|
|
|
|
|
|
+ public function getQueries()
|
|
|
+ {
|
|
|
+ $logger = $this->logger->getDebugLogger();
|
|
|
+
|
|
|
+ if (!$logger) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $offset = strlen(static::LOG_PREFIX);
|
|
|
+ $mapper = function($log) use($offset)
|
|
|
+ {
|
|
|
+ if (0 === strpos($log['message'], DoctrineMongoDBLogger::LOG_PREFIX)) {
|
|
|
+ return substr($log['message'], $offset);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // map queries from logs, remove empty entries and re-index the array
|
|
|
+ return array_values(array_filter(array_map($mapper, $logger->getLogs())));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Formats the supplied query array recursively.
|
|
|
*
|