therealartz/telegram-log-handler

Telegram Handler for Monolog Logger.

v0.1.1 2019-05-18 14:23 UTC

This package is auto-updated.

Last update: 2024-11-19 02:51:39 UTC


README

Latest Stable Version Total Downloads

This package provides Handler for Monolog Logger.

For me in some cases it's very convenient to receive logs in Telegram, so I wrote a short handler for using in any project.

Requirements

  • PHP 7.1+
  • cURL and mbstring extensions activated

Usage

Set up handler

<?php

use Monolog\Logger;
use TelegramLog\Handler\TelegramHandler;

$botToken = 'your-bot-token';
$chatId = '@yourChatId';

$logger = new Logger(
    'logger_dev',
    [
        new TelegramHandler($botToken, $chatId)
    ]
);

$logger->info('My logger works!');

Set up handler in Laravel

According to Laravel docs in config/logging.php add channel:

return [

    // ...
    
    'channels' => [
    
        // ...
        
        'telegram' => [
            'driver' => 'monolog',
            'handler' => \TelegramLog\Handler\TelegramHandler::class,
            'with' => [
                'botToken' => 'your-bot-token',
                'chatId' => '@yourChatId',
            ],
        ],
    ],
];

And use by set in .env LOG_CHANNEL=telegram