Skip to content

Commit 8db8b4b

Browse files
committed
handle exception
1 parent c30cf2d commit 8db8b4b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,23 @@ private function sendToElasticsearch(array $records)
116116

117117
$this->responses->attach($response);
118118

119-
foreach ($this->client->stream($this->responses, 0) as $response => $chunk) {
120-
if (!$chunk->isTimeout() && $chunk->isFirst()) {
121-
$this->responses->detach($response);
119+
try {
120+
foreach ($this->client->stream($this->responses, 0) as $response => $chunk) {
121+
if (!$chunk->isTimeout() && $chunk->isFirst()) {
122+
$this->responses->detach($response);
123+
}
122124
}
125+
} catch (\Throwable $e) {
126+
error_log(sprintf('Could not push logs to elasticsearch: %s', (string) $e));
127+
}
128+
}
129+
130+
public function __destruct()
131+
{
132+
try {
133+
unset($this->responses);
134+
} catch (\Throwable $e) {
135+
error_log(sprintf('Could not push logs to elasticsearch: %s', (string) $e));
123136
}
124137
}
125138
}

0 commit comments

Comments
 (0)