diff --git a/config/debugbar.php b/config/debugbar.php index 3cb4f654..64434fee 100644 --- a/config/debugbar.php +++ b/config/debugbar.php @@ -258,6 +258,7 @@ ], 'events' => [ 'data' => env('DEBUGBAR_OPTIONS_EVENTS_DATA', false), // Collect events data, listeners + 'excluded' => [], // Example: ['eloquent.*', 'composing', Illuminate\Cache\Events\CacheHit::class] ], 'logs' => [ 'file' => env('DEBUGBAR_OPTIONS_LOGS_FILE', null), diff --git a/src/DataCollector/EventCollector.php b/src/DataCollector/EventCollector.php index b36673ac..5dfff86b 100644 --- a/src/DataCollector/EventCollector.php +++ b/src/DataCollector/EventCollector.php @@ -13,16 +13,20 @@ class EventCollector extends TimeDataCollector /** @var Dispatcher */ protected $events; + /** @var Dispatcher */ + protected $excludedEvents; + /** @var integer */ protected $previousTime; /** @var bool */ protected $collectValues; - public function __construct($requestStartTime = null, $collectValues = false) + public function __construct($requestStartTime = null, $collectValues = false, $excludedEvents = []) { parent::__construct($requestStartTime); $this->collectValues = $collectValues; + $this->excludedEvents = $excludedEvents; $this->setDataFormatter(new SimpleFormatter()); } @@ -31,6 +35,12 @@ public function onWildcardEvent($name = null, $data = []) $currentTime = microtime(true); $eventClass = explode(':', $name)[0]; + foreach ($this->excludedEvents as $excludedEvent) { + if (Str::is($excludedEvent, $eventClass)) { + return; + } + } + if (! $this->collectValues) { $this->addMeasure($name, $currentTime, $currentTime, [], null, $eventClass); diff --git a/src/LaravelDebugbar.php b/src/LaravelDebugbar.php index 71cc0786..ede781a0 100644 --- a/src/LaravelDebugbar.php +++ b/src/LaravelDebugbar.php @@ -276,7 +276,8 @@ function () use ($startTime) { try { $startTime = $app['request']->server('REQUEST_TIME_FLOAT'); $collectData = $config->get('debugbar.options.events.data', false); - $this->addCollector(new EventCollector($startTime, $collectData)); + $excludedEvents = $config->get('debugbar.options.events.excluded', []); + $this->addCollector(new EventCollector($startTime, $collectData, $excludedEvents)); $events->subscribe($this['event']); } catch (Exception $e) { $this->addCollectorException('Cannot add EventCollector', $e);