added a configuraiton to allow the profiler to be enabled only when an exception occurs
This commit is contained in:
parent
1e1a4113c7
commit
60ea1eef69
@ -81,6 +81,12 @@ class WebExtension extends Extension
|
|||||||
$loader->load('profiling.xml');
|
$loader->load('profiling.xml');
|
||||||
$loader->load('collectors.xml');
|
$loader->load('collectors.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($config['profiler']['only-exceptions'])) {
|
||||||
|
$container->setParameter('profiler_listener.only_exceptions', $config['profiler']['only-exceptions']);
|
||||||
|
} elseif (isset($config['profiler']['only_exceptions'])) {
|
||||||
|
$container->setParameter('profiler_listener.only_exceptions', $config['profiler']['only_exceptions']);
|
||||||
|
}
|
||||||
} elseif ($container->hasDefinition('profiler')) {
|
} elseif ($container->hasDefinition('profiler')) {
|
||||||
$container->getDefinition('profiling')->clearTags();
|
$container->getDefinition('profiling')->clearTags();
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
<parameter key="profiler.storage.file">%kernel.cache_dir%/profiler.db</parameter>
|
<parameter key="profiler.storage.file">%kernel.cache_dir%/profiler.db</parameter>
|
||||||
<parameter key="profiler.storage.lifetime">86400</parameter>
|
<parameter key="profiler.storage.lifetime">86400</parameter>
|
||||||
<parameter key="profiler_listener.class">Symfony\Component\HttpKernel\Profiler\ProfilerListener</parameter>
|
<parameter key="profiler_listener.class">Symfony\Component\HttpKernel\Profiler\ProfilerListener</parameter>
|
||||||
|
<parameter key="profiler_listener.only_exceptions">false</parameter>
|
||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
@ -27,6 +28,7 @@
|
|||||||
<service id="profiler_listener" class="%profiler_listener.class%">
|
<service id="profiler_listener" class="%profiler_listener.class%">
|
||||||
<tag name="kernel.listener" />
|
<tag name="kernel.listener" />
|
||||||
<argument type="service" id="profiler" />
|
<argument type="service" id="profiler" />
|
||||||
|
<argument>%profiler_listener.only_exceptions%</argument>
|
||||||
</service>
|
</service>
|
||||||
</services>
|
</services>
|
||||||
</container>
|
</container>
|
||||||
|
@ -25,15 +25,18 @@ class ProfilerListener
|
|||||||
{
|
{
|
||||||
protected $profiler;
|
protected $profiler;
|
||||||
protected $exception;
|
protected $exception;
|
||||||
|
protected $onlyException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param Profiler $profiler A Profiler instance
|
* @param Profiler $profiler A Profiler instance
|
||||||
|
* @param Boolean $onlyException true if the profiler only collects data when an exception occurs, false otherwise
|
||||||
*/
|
*/
|
||||||
public function __construct(Profiler $profiler)
|
public function __construct(Profiler $profiler, $onlyException = false)
|
||||||
{
|
{
|
||||||
$this->profiler = $profiler;
|
$this->profiler = $profiler;
|
||||||
|
$this->onlyException = $onlyException;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,6 +80,10 @@ class ProfilerListener
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->onlyException && null === $this->exception) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
$this->profiler->collect($event->getParameter('request'), $response, $this->exception);
|
$this->profiler->collect($event->getParameter('request'), $response, $this->exception);
|
||||||
$this->exception = null;
|
$this->exception = null;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user