PHPackages                             jacklul/monolog-telegram - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. jacklul/monolog-telegram

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

jacklul/monolog-telegram
========================

Monolog handler that sends logs through Telegram bot to any chat in HTML format

3.2.0(1y ago)2364.7k↓11%7[1 PRs](https://github.com/jacklul/monolog-telegram/pulls)1MITPHPPHP ^8.1CI failing

Since Feb 22Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/jacklul/monolog-telegram)[ Packagist](https://packagist.org/packages/jacklul/monolog-telegram)[ RSS](/packages/jacklul-monolog-telegram/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (17)Used By (1)

Monolog Telegram Handler
========================

[](#monolog-telegram-handler)

Send your logs through Telegram bot to any chat and make them look fancy!

#### Features:

[](#features)

- [Continous logging](https://i.imgur.com/8EnxO90.jpg) and [batch logging](https://i.imgur.com/4C9Y6cT.jpg) support
- Standard stack traces wrapped in `` tags
- Automatic splitting of the message when it exceeds maximum limit

Prerequisites
-------------

[](#prerequisites)

- Telegram Bot API token - [see here](https://core.telegram.org/bots#creating-a-new-bot) to learn how to obtain one
- ID of the chat to which you want to send the logs - see below

#### Obtaining chat ID

[](#obtaining-chat-id)

One of the simplest ways to do that is to interact with the bot in the target chat:

- private and group chats - send any dummy command
- channels - post something in it

After interacting visit `https://api.telegram.org/botTOKEN/getUpdates` (replace `TOKEN` with your actual bot token), you will be able to find the chat id (`chat_id`) in the result JSON.

Installation
------------

[](#installation)

Install with [Composer](https://github.com/composer/composer):

```
$ composer require jacklul/monolog-telegram
```

Usage
-----

[](#usage)

To use this handler you just have to add it like every other **Monolog** handler:

```
require 'vendor/autoload.php';

$logger = new Logger('My project');
$handler = new TelegramHandler(
    '123456789:teMbvbETojnSG93jDhnynvH8pT28H9TIB1h',  // Bot API token
    987654321,  // Target Chat ID
    Logger::ERROR,  // Log level, default: DEBUG
    true,  // Bubble up the stack or not, default: true
    true,  // Use cURL or not? default: true = use when available
    10,    // Timeout for API requests, default: 10
    true   // Verify SSL certificate or not? default: true, false only useful for development - avoid in production
    2,     // (optional) Target Thread ID for group chats with Topics enabled
);

$handler->setFormatter(new TelegramFormatter());    // Usage of this formatter is optional but recommended if you want better message layout
$logger->pushHandler($handler);

$logger->error('Error!');
```

To prevent spamming the chat and hitting Telegram's API limits it is advised to use [DeduplicationHandler](https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/DeduplicationHandler.php) and/or [BufferHandler](https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/BufferHandler.php), ideal solution for production use would be:

```
$handler = new TelegramHandler('TOKEN', 123456789);
$handler->setFormatter(new TelegramFormatter());

// Combine all log entries into one and force batch processing
$handler = new BufferHandler($handler);

// Make sure that particular log stack wasn't sent before
$handler = new DeduplicationHandler($handler);

// Keep collecting logs until ERROR occurs, after that send collected logs to $handler
$handler = new FingersCrossedHandler($handler, new ErrorLevelActivationStrategy(Logger::ERROR));

$logger->pushHandler($handler);
```

You can customize the formatter:

```
$html = true;    // Choose whether to send the message in HTMl format
$format = "%emoji% %level_name% (%channel%) [%date%]\n\n%message%\n\n%context%%extra%";   // EMOJI ERROR (My project) [2018-05-01 15:55:15 UTC]
$date_format = 'Y-m-d H:i:s e';       // 2018-05-01 15:55:15 UTC, format must be supported by DateTime::format
$separator = '-';       // Seperation character for batch processing - when empty one empty line is used
$emojis = [         // Override any level emoji
    'NOTICE' => '🤖'
];

$handler->setFormatter(new TelegramFormatter($html, $format, $date_format, $separator, $emojis));
```

Running tests
-------------

[](#running-tests)

Create `.env` file:

```
TELEGRAM_TOKEN=BOT_TOKEN
TELEGRAM_CHAT_ID=CHAT_ID_THE_BOT_WILL_SPAM;

```

Run `composer check-code` and `composer test`.

License
-------

[](#license)

See [LICENSE](LICENSE).

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance63

Regular maintenance activity

Popularity41

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 81.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~180 days

Recently: every ~450 days

Total

15

Last Release

479d ago

Major Versions

1.4.0 → 2.0.02020-02-19

2.1.0 → 3.0.02023-01-31

PHP version history (4 changes)1.0.0PHP ^5.5|^7.0

2.0.0PHP ^7.2

2.1.0PHP ^7.2|^8.0

3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c5d190f1856db1e9c39d095b0eadd550475fd09d658d38c015c4631a10748f3?d=identicon)[jacklul](/maintainers/jacklul)

---

Top Contributors

[![jacklul](https://avatars.githubusercontent.com/u/8418678?v=4)](https://github.com/jacklul "jacklul (48 commits)")[![Niklan](https://avatars.githubusercontent.com/u/2356744?v=4)](https://github.com/Niklan "Niklan (8 commits)")[![paulo-hortelan](https://avatars.githubusercontent.com/u/135706260?v=4)](https://github.com/paulo-hortelan "paulo-hortelan (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

monologmonolog-handlertelegramlogloggingbottelegrammonolog

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jacklul-monolog-telegram/health.svg)

```
[![Health](https://phpackages.com/badges/jacklul-monolog-telegram/health.svg)](https://phpackages.com/packages/jacklul-monolog-telegram)
```

###  Alternatives

[rahimi/monolog-telegram

A handler for Monolog that sends messages to Telegram Channels

6980.2k1](/packages/rahimi-monolog-telegram)[inpsyde/wonolog

Monolog-based logging package for WordPress.

183617.9k7](/packages/inpsyde-wonolog)[mero/telegram-handler

Monolog handler to send log by Telegram

36113.3k](/packages/mero-telegram-handler)[thecoder/laravel-monolog-telegram

Telegram Handler for Monolog

2939.5k](/packages/thecoder-laravel-monolog-telegram)[logtail/monolog-logtail

Logtail handler for Monolog

233.2M3](/packages/logtail-monolog-logtail)[inpsyde/logzio-monolog

Logz.io integration for Monolog

191.2M1](/packages/inpsyde-logzio-monolog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
