Skip to content

Commit

Permalink
Merge pull request #1 from pvanliefland/raven-improvements
Browse files Browse the repository at this point in the history
Amended PR #203 (RavenHandler batch improvements)
  • Loading branch information
fabpot committed Jul 11, 2013
2 parents 29ae147 + 474a0f7 commit 6dd92e4
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Monolog/Handler/RavenHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,25 @@ public function __construct(Raven_Client $ravenClient, $level = Logger::DEBUG, $
*/
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);
}

Expand Down

0 comments on commit 6dd92e4

Please sign in to comment.