swarletta/telegram-logger

There is no license information available for the latest version (v1.0.1) of this package.

Handle your errors into Telegram

Installs: 10

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/swarletta/telegram-logger

v1.0.1 2021-02-07 17:33 UTC

This package is not auto-updated.

Last update: 2025-10-28 14:12:16 UTC


README

Send error logs from your project to Telegram bot. Based on monolog/monolog

Install with Composer

composer require swarletta/telegram-logger

Initialization

First, you need to create an instance of TelegramHandler class. You will need a token to your Telegram Bot, chat ID to create the instance. Error LEVEL is set to DEBUG by default.

$handler = new TelegramHandler($token, $chat_id, Logger::DEBUG);

Then call method setFormatter to create a message.

$handler->setFormatter(new LineFormatter("%message%", null, true));

Here is an example of Logger call

<?php

require 'vendor/autoload.php';

use App\TelegramHandler;
use Monolog\Formatter\LineFormatter;
use Monolog\Logger;

$token = '000000000:XXXXX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$chat_id = 999999999;
$log = new Logger('telegram-channel');

$handler = new TelegramHandler($token, $chat_id, Logger::DEBUG);
$handler->setFormatter(new LineFormatter("%message%", null, true));
$log->pushHandler($handler);

$log->debug('Test message');