gh-rboliveira/monolog-telegram

A handler for Monolog that sends messages to Telegram Channels

2.0.4 2018-02-09 18:34 UTC

This package is not auto-updated.

Last update: 2025-07-09 07:31:08 UTC


README

Install using composer:

composer require gh-rboliveira/monolog-telegram  

Usage

it is just like other monolog handlers, you need to pass below optional paramaters to telegramhandler object:

  • $level - The minimum logging level at which this handler will be triggered
  • $bubble - Whether the messages that are handled can bubble up the stack or not

Examples

Now Simply use it like this :

require 'vendor/autoload.php';
use Monolog\Logger;
use gh_rboliveira\TelegramHandler\TelegramHandler;

$log = new Logger('TelegramHandler');
//Create handler
$telegramHandler = new TelegramHandler();

//Add $token - your bot token provided by BotFather
$token = 'XXXXXXXXX:qeQWLElwe_m232WE1K3WEe323eeTw';
$telegramHandler->setBotToken($token);

//Set Receipts - an array with telegram ids
$recipients = ['123456789','987654321'];
$telegramHandler->setRecipients($recipients);

//Set Handler
$log->pushHandler($telegramHandler);

$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 parameter 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 !