PHP code example of ryanda / monolog-telegram

1. Go to this page and download the library: Download ryanda/monolog-telegram library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ryanda / monolog-telegram example snippets




onolog\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');

...
'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'),
        ],
    ]
]
...

'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'),
    ],
]