merged branch willdurand/propel-stopwatch (PR #3352)
Commits
-------
b3fd2fa
[Propel] Added Propel to Stopwatch
Discussion
----------
[Propel] Added Propel to Stopwatch
I've added the Stopwatch feature, everything is ready on the PropelBundle.
The trick is to log `prepare` queries in Propel, that way we got first the prepared statement, and then the executed query. That's why there is a `$isPrepare` boolean.
I kept BC if people don't update the PropelBundle too.
William
---------------------------------------------------------------------------
by stof at 2012-02-14T12:16:51Z
@willdurand toggling a flag for each call seems a bit hackish to me. Is there no better way to do it ?
---------------------------------------------------------------------------
by willdurand at 2012-02-14T12:21:38Z
Unfortunately no... But it's quite safe as we cannot change logged methods.
There is neighter start/stop methods, nor typed messages.
Le 14 févr. 2012 à 13:16, Christophe Coevoet<reply@reply.github.com> a écrit :
> @willdurand toggling a flag for each call seems a bit hackish to me. Is there no better way to do it ?
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/symfony/symfony/pull/3352#issuecomment-3959592
---------------------------------------------------------------------------
by stof at 2012-02-14T12:26:04Z
@willdurand then let's use this for propel 1. But please improve the logging interface for Propel 2 :)
---------------------------------------------------------------------------
by willdurand at 2012-02-14T12:34:28Z
Sure! I've added that on my todolist…
2012/2/14 Christophe Coevoet <
reply@reply.github.com
>
> @willdurand then let's use this for propel 1. But please improve the
> logging interface for Propel 2 :)
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/symfony/symfony/pull/3352#issuecomment-3959729
>
This commit is contained in:
commit
b8322b306a
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Bridge\Propel1\Logger;
|
||||
|
||||
use Symfony\Component\HttpKernel\Debug\Stopwatch;
|
||||
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
@ -31,15 +32,25 @@ class PropelLogger
|
||||
*/
|
||||
protected $queries;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\HttpKernel\Debug\Stopwatch
|
||||
*/
|
||||
protected $stopwatch;
|
||||
|
||||
private $isPrepare;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param LoggerInterface $logger A LoggerInterface instance
|
||||
* @param Stopwatch $stopwatch A Stopwatch instance
|
||||
*/
|
||||
public function __construct(LoggerInterface $logger = null)
|
||||
public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch = null)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->queries = array();
|
||||
$this->stopwatch = $stopwatch;
|
||||
$this->isPrepare = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,11 +132,27 @@ class PropelLogger
|
||||
*/
|
||||
public function debug($message)
|
||||
{
|
||||
$add = true;
|
||||
|
||||
if (null !== $this->stopwatch) {
|
||||
if ($this->isPrepare) {
|
||||
$this->stopwatch->start('propel', 'propel');
|
||||
$this->isPrepare = false;
|
||||
|
||||
$add = false;
|
||||
} else {
|
||||
$this->stopwatch->stop('propel');
|
||||
$this->isPrepare = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($add) {
|
||||
$this->queries[] = $message;
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->debug($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns queries.
|
||||
|
@ -8,6 +8,7 @@
|
||||
'event_listener_loading': '#add',
|
||||
'template': '#dd3',
|
||||
'doctrine': '#d3d',
|
||||
'propel': '#f4d',
|
||||
'child_sections': '#eed',
|
||||
} %}
|
||||
{% endif %}
|
||||
|
Reference in New Issue
Block a user