php-core / simple-telegram-log
A simple Telegram logging helper for PHP
Installs: 77
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/php-core/simple-telegram-log
Requires (Dev)
- vlucas/phpdotenv: ^5.6
This package is auto-updated.
Last update: 2025-10-03 10:42:50 UTC
README
A simple Telegram logging helper for PHP
Usage
composer require php-core/simple-telegram-log
Examples:
Using environment vars (short usage)
use PHPCore\SimpleTelegramLog\TGLog; require_once dirname(__DIR__) . '/vendor/autoload.php'; TGLog::logMessage('Test message');
In code (flexible usage)
use PHPCore\SimpleTelegramLog\TGLog; require_once dirname(__DIR__) . '/vendor/autoload.php'; TGLog::init( '123456:124334534534', // tg bot token -14943993494, // tg chat id null, // tg channel topic id false // debug mode )->sendMessage('Test message');
Logging a PHP "Exception/Throwable"
use PHPCore\SimpleTelegramLog\TGLog; require_once dirname(__DIR__).'/vendor/autoload.php'; TGLog::logException(new Exception('Test exception'));
Log request dump
use PHPCore\SimpleTelegramLog\TGLog; require_once dirname(__DIR__).'/vendor/autoload.php'; TGLog::logRequestDump();
Debug log
use PHPCore\SimpleTelegramLog\TGLog; require_once dirname(__DIR__).'/vendor/autoload.php'; TGLog::debugLogMessage('This message will only be logged if debug mode is on');
Using custom Bot API
use PHPCore\SimpleTelegramLog\TGLog; require_once dirname(__DIR__).'/vendor/autoload.php'; TGLog::init( '123456:124334534534', // tg bot token -14943993494, // tg chat id null, // tg channel topic id false, // debug mode 'https://tg-bot-api.php-core.com' // custom Bot API server url )->sendMessage('Test message');
Using a cli program for HTTP requests (requires ability to run PHP's "exec" function and a cli program like "wget" installed)
use PHPCore\SimpleTelegramLog\TGLog; require_once dirname(__DIR__).'/vendor/autoload.php'; TGLog::init( '123456:124334534534', // tg bot token -14943993494, // tg chat id null, // tg channel topic id false, // debug mode TGLog::API_BASE_URL, // custom Bot API server url 'wget' // (or "curl") the cli program to use for the HTTP request )->sendMessage('Test message');
Using a cli program with nohup for HTTP requests (requires ability to run PHP's "exec" function and "nohup" as well as a cli program like "wget" installed)
use PHPCore\SimpleTelegramLog\TGLog; require_once dirname(__DIR__).'/vendor/autoload.php'; TGLog::init( '123456:124334534534', // tg bot token -14943993494, // tg chat id null, // tg channel topic id false, // debug mode TGLog::API_BASE_URL, // custom Bot API server url 'exec nohup setsid wget' // (or "curl") the cli program to use for the HTTP request )->sendMessage('Test message');
Optional Environment Variables for simple use:
Variable | Default | Description |
---|---|---|
DEBUG | false | "true" or "false" enables or disables debug mode |
TG_LOG_BOT_TOKEN | x | The default bot token to use for sending log messages |
TG_LOG_CHAT_ID | x | The default chat ID to send log messages to |
TG_LOG_TOPIC_ID | x | The default channel topic ID to send log messages to |
TG_LOG_BOT_SERVER_URL | https://api.telegram.org | The base URL of the Bot API to use |
TG_LOG_BOT_HTTP_CMD | x | Optional cli program to use in PHP's "exec" function for HTTP requests (e.g "curl" or "wget") |