From 474a0f7bc4af829fae714b517575926c93973a69 Mon Sep 17 00:00:00 2001 From: pvanliefland Date: Thu, 11 Jul 2013 19:16:14 +0200 Subject: [PATCH] Amended PR #203 (RavenHandler batch improvements) Filtered records based on their level Took the record with the highest severity as the main one --- src/Monolog/Handler/RavenHandler.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Monolog/Handler/RavenHandler.php b/src/Monolog/Handler/RavenHandler.php index 66207e84..48f8f298 100644 --- a/src/Monolog/Handler/RavenHandler.php +++ b/src/Monolog/Handler/RavenHandler.php @@ -66,20 +66,25 @@ class RavenHandler extends AbstractProcessingHandler */ public function handleBatch(array $records) { - // the last records is the "main" one - $record = array_pop($records); + $level = $this->level; - // no need to go further if the main record is not at the right level - if ($record['level'] < $this->level) { - return; - } + // filter records based on their level + $records = array_filter($records, function($record) use($level) { + return $record['level'] >= $level; + }); + + // the record with the highest severity is the "main" one + $record = array_reduce($records, function($highest, $record) { + if($record['level'] >= $highest['level']) { + $highest = $record; + + return $highest; + } + }); // the other ones are added as a context item $logs = array(); foreach ($records as $r) { - if ($r['level'] < $this->level) { - continue; - } $logs[] = $this->processRecord($r); }