Skip to content

Commit

Permalink
ограничил макс длинну сообщения в телегу
Browse files Browse the repository at this point in the history
mttzzz committed Apr 27, 2020
1 parent 1a26965 commit 57a137d
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 2 additions & 4 deletions HandlerTelegramLogger.php
Original file line number Diff line number Diff line change
@@ -13,12 +13,10 @@ public function isHandling(array $record): bool

public function handle(array $record): bool
{
Telegram::log([
'message' => $record['message']
]);
Telegram::log(['message' => $record['message']]);
return true;
}
}
{

}
}
13 changes: 9 additions & 4 deletions Telegram.php
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ public static function log($note)
{
if ($note instanceof Exception) {
$note = [
'message' => $note->getMessage(),
'message' => self::stLimit($note->getMessage()),
'line' => $note->getLine(),
'file' => $note->getFile()
];
@@ -34,17 +34,17 @@ public static function log($note)
$note = json_encode($note, 64 | 128 | 256 | 2048);
} else {

$noteArray = json_decode(urldecode($note),1);
$noteArray = json_decode(urldecode($note), 1);
if (json_last_error() == JSON_ERROR_NONE) {
$note = json_encode($noteArray, 64 | 128 | 256 | 2048 );
$note = json_encode($noteArray, 64 | 128 | 256 | 2048);
}
}
$token = config('telegramLog.token');
$chat_id = config('telegramLog.chat_id');
$message = '<b>' . env('APP_NAME') . '</b>' . PHP_EOL
. '<b>' . env('APP_ENV') . '</b>' . PHP_EOL
. '<i>Message:</i>' . PHP_EOL
. '<code>' . $note . '</code>';
. '<code>' . self::stLimit($note) . '</code>';

try {
$ids = explode(',', $chat_id);
@@ -64,4 +64,9 @@ public static function log($note)

}
}

public static function stLimit($m)
{
return mb_strlen($m) > 1300 ? mb_substr($m, 0, 1300) . '...' : $m;
}
}

0 comments on commit 57a137d

Please sign in to comment.