1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-18 15:18:08 +02:00

Include record message/context/extra data when throwing an exception because the log cannot be opened, fixes #1630

This commit is contained in:
Jordi Boggiano
2022-03-14 13:34:54 +01:00
parent e289293a7c
commit c02d86ffb2
7 changed files with 39 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ namespace Monolog\Handler;
use RuntimeException;
use Monolog\Logger;
use Monolog\Utils;
/**
* Handler send logs to Telegram using Telegram Bot API.
@@ -247,12 +248,12 @@ class TelegramBotHandler extends AbstractProcessingHandler
$result = Curl\Util::execute($ch);
if (!is_string($result)) {
throw new RuntimeException('Telegram API error. Description: No response');
throw new RuntimeException('Telegram API error. Description: No response' . Utils::getRecordMessageForException($record));
}
$result = json_decode($result, true);
if ($result['ok'] === false) {
throw new RuntimeException('Telegram API error. Description: ' . $result['description']);
throw new RuntimeException('Telegram API error. Description: ' . $result['description'] . Utils::getRecordMessageForException($record));
}
}
@@ -265,7 +266,7 @@ class TelegramBotHandler extends AbstractProcessingHandler
{
$truncatedMarker = ' (...truncated)';
if (!$this->splitLongMessages && strlen($message) > self::MAX_MESSAGE_LENGTH) {
return [substr($message, 0, self::MAX_MESSAGE_LENGTH - strlen($truncatedMarker)) . $truncatedMarker];
return [Utils::substr($message, 0, self::MAX_MESSAGE_LENGTH - strlen($truncatedMarker)) . $truncatedMarker];
}
return str_split($message, self::MAX_MESSAGE_LENGTH);