codelikesuraj / lograh-php
A light-weight logger that logs to Telegram.
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/codelikesuraj/lograh-php
Requires
- php: >=8.0
This package is auto-updated.
Last update: 2025-12-20 16:54:43 UTC
README
LograhPHP sends your exceptions to Telegram chats, channels or groups.
Requirements
- 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.
Installation
$ composer require codelikesuraj/lograh-php
Basic Usage
Sample code
<?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 ... }
Sample response message sent to Telegram
Report as TEXT
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:#
Report as JSON
{
"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:#",
}
Report as JSON WITH STACK TRACE
{
"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}"
]
}
Author
Abdulbaki Suraj - http://twitter.com/fliplikesuraj
License
LograhPHP is licensed under the MIT License.