Monolog Handler sends your logs to Telegram Channel via Bot.
- PHP 5.6 or above
- cURL extension
Install using composer
$ composer require ryanda/monolog-telegram
<?php
require __DIR__ . '/vendor/autoload.php';
use Monolog\Logger;
use Ryanda\MonologTelegram\TelegramBotHandler;
// create a log channel
$log = new Logger('name');
$log->pushHandler(new TelegramBotHandler('YOUR_API_KEY', 'YOUR_CHANNEL_ID', Logger::WARNING));
// push to the channel
$log->warning('Foo');
$log->error('Bar');
Open up config/logging.php
and find the channels key. Add the following channel to the list.
...
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['telegram'],
],
....
'telegram' => [
'driver' => 'monolog',
'handler' => \Ryanda\MonologTelegram\TelegramBotHandler::class,
'formatter' => \Ryanda\MonologTelegram\TelegramFormatter::class,
'with' => [
'apiKey' => env('TELEGRAM_BOT_API'),
'channel' => env('TELEGRAM_BOT_CHANNEL'),
],
]
]
...
Add the following information to your .env
file. Your TELEGRAM_BOT_API is the bot key and TELEGRAM_BOT_CHANNEL is the chat ID for a telegram user or channel.
TELEGRAM_BOT_API=123456789:ABCDEFGHIJKLMNOPQUSTUFWXYZabcdefghi
TELEGRAM_BOT_CHANNEL=12345678
If you want to add extra information, you can use tap
feature on Laravel, by passing it as array.
'telegram' => [
'driver' => 'monolog',
'handler' => \Ryanda\MonologTelegram\TelegramBotHandler::class,
'formatter' => \Ryanda\MonologTelegram\TelegramFormatter::class,
'tap' => [\App\Exceptions\TelegramTap::class],
'with' => [
'apiKey' => env('TELEGRAM_BOT_API'),
'channel' => env('TELEGRAM_BOT_CHANNEL'),
],
]
See LICENSE.