Permalink
Browse files

monologsqllogger

  • Loading branch information...
1 parent 832e1f1 commit bbb678c85edcae3095462eee79b61d8528a04c05 @Mparaiso committed Mar 24, 2013
Showing with 52 additions and 0 deletions.
  1. +52 −0 src/Mparaiso/Doctrine/ORM/Logger/MonologSQLLogger.php
@@ -0,0 +1,52 @@
+<?php
+
+/**
+ * @author M.Paraiso <mparaiso@online.fr>
+ */
+
+namespace Mparaiso\Doctrine\ORM\Logger{
+
+ use Doctrine\DBAL\Logging\SQLLogger;
+ use Monolog\Logger;
+
+ /**
+ * FR : log les requêtes de la base de donnée
+ */
+ class MonologSQLLogger implements SQLLogger {
+
+ /**
+ * Monolog logger
+ * @var Monolog\Logger $_logger
+ */
+ protected $_logger;
+
+ /**
+ *
+ * @var integer $_startTime
+ */
+ protected $_startTime;
+
+ /**
+ *
+ * @param \Monolog\Logger $logger
+ */
+ public function __construct(Logger $logger) {
+ $this->_logger = $logger;
+ }
+
+ public function startQuery($sql, array $params = null, array $types = null) {
+ $this->_logger->addInfo($sql);
+ if ($params!=null)
+ $this->_logger->addInfo(print_r($params, true));
+ if ($types!=null)
+ $this->_logger->addInfo(print_r($types, true));
+ $this->_startTime = microtime();
+ }
+
+ public function stopQuery() {
+ $this->_logger->addInfo("Query duration : " .$this->_startTime - microtime() . "ms");
+ }
+
+ }
+
+}

0 comments on commit bbb678c

Please sign in to comment.