Skip to content

Commit

Permalink
Merge pull request #294 from CakeDC/3.x
Browse files Browse the repository at this point in the history
Fix elastic logger to avoid debug kit panel exception
  • Loading branch information
markstory authored Sep 9, 2022
2 parents 76444aa + b560bc9 commit f52cd04
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Datasource/Log/ElasticLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,21 @@ protected function _log($level, $message, array $context = [])
$logData = json_encode($logData, JSON_PRETTY_PRINT);

if (isset($context['request'], $context['response'])) {
$took = $numRows = 0;
$took = 0;
$numRows = $context['response']['hits']['total']['value'] ?? $context['response']['hits']['total'] ?? 0;
if (isset($context['response']['took'])) {
$took = $context['response']['took'];
}
if (isset($context['response']['hits']['total'])) {
$numRows = $context['response']['hits']['total'];
}
$message = new LoggedQuery();
$message->query = $logData;
$message->took = $took;
$message->numRows = $numRows;

$context['query'] = $message;
}
$exception = $context['exception'] ?? null;
if ($exception instanceof \Exception) {
throw $exception;
}
$this->getLogger()->log($level, $logData, $context);
}
}

0 comments on commit f52cd04

Please sign in to comment.