From 860b504884caf4fcc3969803d259bebc6f824dc3 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 24 Jan 2024 23:08:14 -0500 Subject: [PATCH] Improve log integration for elasticearch Not all queries have 'took'. Account for that and use defaults values. Fixes #989 --- src/Database/Log/DebugLog.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Database/Log/DebugLog.php b/src/Database/Log/DebugLog.php index 3e069f4d..ed93e911 100644 --- a/src/Database/Log/DebugLog.php +++ b/src/Database/Log/DebugLog.php @@ -135,7 +135,8 @@ public function log($level, string|Stringable $message, array $context = []): vo // This specific to Elastic Search if (!$query instanceof LoggedQuery && isset($context['request']) && isset($context['response'])) { - $this->_totalTime += $context['response']['took']; + $took = $context['response']['took'] ?? 0; + $this->_totalTime += $took; $this->_queries[] = [ 'query' => json_encode([ @@ -143,7 +144,7 @@ public function log($level, string|Stringable $message, array $context = []): vo 'path' => $context['request']['path'], 'data' => $context['request']['data'], ], JSON_PRETTY_PRINT), - 'took' => $context['response']['took'] ?: 0, + 'took' => $took ?: 0, 'rows' => $context['response']['hits']['total']['value'] ?? $context['response']['hits']['total'] ?? 0, ];