LograhPHP sends your exceptions to Telegram chats, channels or groups.
- PHP 8.0 or above.
- php_curl extension enabled.
- A Telegram bot's access token and chat/channel/group id. Generate a Telegram bot with https://telegram.me/BotFather.
$ composer require codelikesuraj/lograh-php
<?php
use Codelikesuraj\LograhPHP\Logger;
// initialize logger with your Telegram bot credentials
$logger = new Logger(
appName: "unique_name_to_identify_your_app",
botToken: "api_key_generated_from_your_telegram_bot",
chatId: "id_of_your_telegram_chat_or_channel_or_group"
);
try {
// code that may generate an exception
...
} catch (\Throwable $exception) {
// optional list of exceptions to be ignored
$logger->ignore([ExceptionA::class, ExceptionB::class]);
// send exception to Telegram using any
// of the following methods
$logger->reportAsText($exception);
$logger->reportAsJson($exception);
$logger->reportAsJsonWithStackTrace($exception);
// further processing
...
}
app: unique_name_to_identify_your_app
timestamp: 0000-00-00 00:00:00 +0000
"summary": Uncaught exception: 'exception_name' with message 'exception_message' in /path/to/folder/file.php:#
{
"app": "unique_name_to_identify_your_app",
"timestamp": "0000-00-00 00:00:00 +0000",
"summary": "Uncaught exception: 'exception_name' with message 'exception_message' in \/path\/to\/folder\/file.php:#",
}
{
"app": "unique_name_to_identify_your_app",
"timestamp": "0000-00-00 00:00:00 +0000",
"summary": "Uncaught exception: 'exception_name' with message 'exception_message' in \/path\/to\/folder\/file.php:#",
"stack trace": [
"#0 {main}"
]
}
Abdulbaki Suraj - http://twitter.com/fliplikesuraj
LograhPHP is licensed under the MIT License.