rahimi / monolog-telegram
A handler for Monolog that sends messages to Telegram Channels
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 80 121
Dependents: 2
Suggesters: 1
Security: 0
Stars: 69
Watchers: 3
Forks: 10
Open Issues: 2
Requires
- ext-curl: *
- ext-json: *
- monolog/monolog: ~2
This package is auto-updated.
Last update: 2024-07-16 15:19:00 UTC
README
Telegram Handler for php monolog which allows you to log messages into telegram channels using bots .
Screenshot
Installation
Install using composer:
composer require rahimi/monolog-telegram
Usage
it is just like other monolog handlers, you need to pass below paramaters to telegramhandler object:
- $token your bot token provided by BotFather
- $channel your telegram channel userName
- $date_default_timezone_set is the timezone identifier, like
'UTC'
or 'Europe/Lisbon
', that will be used as the default timezone by all date/time functions (optional, default value'UTC'
) - $dateFormat pass date format (optional, default value
'Y-m-d H:i:s'
) - $timeOut timeout value in seconds for connection to Telegram servers when sending the log message (optional, default value
100
). Use0
to wait indefinitely.
Examples
Now Simply use it like this :
require 'vendor/autoload.php'; use Monolog\Logger; use rahimi\TelegramHandler\TelegramHandler; $log = new Logger('TelegramHandler'); $log->pushHandler(new TelegramHandler($token,$channel,'UTC','F j, Y, g:i a',60)); $log->info('hello world !'); /** * There is 8 level of logging */ $log->notice('hello world !'); $log->info('hello world !'); $log->debug('hello world !'); $log->warning('hello world !'); $log->critical('hello world !'); $log->alert('hello world !'); $log->emergency('hello world !'); $log->error('hello world !'); /** * Optionally you can pass second paramater such as a object **/ $log->info('user just logged in !',['user'=>$user]);
License
This tool in Licensed under MIT, so feel free to fork it and make it better that it is !