Source of file PropelLogger.php
Size: 3,867 Bytes - Last Modified: 2013-07-17T08:22:21+02:00
/home/theseer/Downloads/Symfony/vendor/symfony/symfony/src/Symfony/Bridge/Propel1/Logger/PropelLogger.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 | <?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Bridge\Propel1\Logger; use Symfony\Component\Stopwatch\Stopwatch; use Psr\Log\LoggerInterface; /** * PropelLogger. * * @author Fabien Potencier <fabien.potencier@symfony-project.com> * @author William Durand <william.durand1@gmail.com> */ class PropelLogger { /** * @var LoggerInterface */ protected $logger; /** * @var array */ protected $queries; /** * @var Stopwatch */ protected $stopwatch; private $isPrepared; /** * Constructor. * * @param LoggerInterface $logger A LoggerInterface instance * @param Stopwatch $stopwatch A Stopwatch instance */ public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch = null) { $this->logger = $logger; $this->queries = array(); $this->stopwatch = $stopwatch; $this->isPrepared = false; } /** * A convenience function for logging an alert event. * * @param mixed $message the message to log. */ public function alert($message) { if (null !== $this->logger) { $this->logger->alert($message); } } /** * A convenience function for logging a critical event. * * @param mixed $message the message to log. */ public function crit($message) { if (null !== $this->logger) { $this->logger->critical($message); } } /** * A convenience function for logging an error event. * * @param mixed $message the message to log. */ public function err($message) { if (null !== $this->logger) { $this->logger->error($message); } } /** * A convenience function for logging a warning event. * * @param mixed $message the message to log. */ public function warning($message) { if (null !== $this->logger) { $this->logger->warning($message); } } /** * A convenience function for logging an critical event. * * @param mixed $message the message to log. */ public function notice($message) { if (null !== $this->logger) { $this->logger->notice($message); } } /** * A convenience function for logging an critical event. * * @param mixed $message the message to log. */ public function info($message) { if (null !== $this->logger) { $this->logger->info($message); } } /** * A convenience function for logging a debug event. * * @param mixed $message the message to log. */ public function debug($message) { $add = true; if (null !== $this->stopwatch) { $trace = debug_backtrace(); $method = $trace[2]['args'][2]; $watch = 'Propel Query '.(count($this->queries)+1); if ('PropelPDO::prepare' === $method) { $this->isPrepared = true; $this->stopwatch->start($watch, 'propel'); $add = false; } elseif ($this->isPrepared) { $this->isPrepared = false; $this->stopwatch->stop($watch); } } if ($add) { $this->queries[] = $message; if (null !== $this->logger) { $this->logger->debug($message); } } } /** * Returns queries. * * @return array Queries */ public function getQueries() { return $this->queries; } } |