PHPackages                             salikhov/yii2-telegram-log-target - 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. salikhov/yii2-telegram-log-target

ActiveYii2-extension[Logging &amp; Monitoring](/categories/logging)

salikhov/yii2-telegram-log-target
=================================

Yii2 log target that sends error notifications to Telegram

v1.0.0(4mo ago)032MITPHPPHP &gt;=8.0

Since Jan 5Pushed 4mo agoCompare

[ Source](https://github.com/SalikhovID/yii2-telegram-log-target)[ Packagist](https://packagist.org/packages/salikhov/yii2-telegram-log-target)[ RSS](/packages/salikhov-yii2-telegram-log-target/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Yii2 Telegram Log Target
========================

[](#yii2-telegram-log-target)

A Yii2 log target that sends error notifications to Telegram. Perfect for real-time error monitoring of your Yii2 applications.

Features
--------

[](#features)

- Sends only 5xx server errors and exceptions (no spam from 4xx client errors)
- HTML-formatted messages with error details, file location, and stack trace
- Automatic message chunking for long error messages (Telegram's 4096 char limit)
- Easy configuration via environment variables

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

[](#installation)

```
composer require salikhov/yii2-telegram-log-target
```

Configuration
-------------

[](#configuration)

### 1. Create a Telegram Bot

[](#1-create-a-telegram-bot)

1. Open Telegram and search for [@BotFather](https://t.me/BotFather)
2. Send `/newbot` and follow the instructions
3. Copy the bot token (looks like `123456789:ABCdefGHIjklMNOpqrsTUVwxyz`)

### 2. Get Your Chat ID

[](#2-get-your-chat-id)

1. Start a chat with your bot
2. Send any message to the bot
3. Visit `https://api.telegram.org/bot/getUpdates`
4. Find your `chat_id` in the response

For group chats, add the bot to the group and use the negative group ID.

### 3. Configure Yii2

[](#3-configure-yii2)

Add to your application config (e.g., `config/main.php` or `config/web.php`):

```
'components' => [
    'log' => [
        'targets' => [
            [
                'class' => \Salikhov\TelegramLogTarget\TelegramTarget::class,
                'levels' => ['error'],
                'chat_id' => getenv('TELEGRAM_ERROR_CHAT_ID'),
                'bot_token' => getenv('TELEGRAM_BOT_TOKEN'),
                'title' => 'My App Error', // Optional, defaults to "Error"
            ],
        ],
    ],
],
```

### 4. Set Environment Variables

[](#4-set-environment-variables)

Add to your `.env` file:

```
TELEGRAM_ERROR_CHAT_ID=123456789
TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
```

Configuration Options
---------------------

[](#configuration-options)

OptionTypeDefaultDescription`chat_id`stringnullTelegram chat ID (user, group, or channel)`bot_token`stringnullTelegram bot token from @BotFather`title`string"Error"Title prefix shown in bold at the top`levels`array-Standard Yii2 log levels to captureMessage Format
--------------

[](#message-format)

Error messages are formatted with HTML:

```
**Error**
2024-01-15 14:30:00

Error: Division by zero

File: /var/www/app/controllers/SiteController.php:42

[Stack trace...]

```

Filtering Errors
----------------

[](#filtering-errors)

By default, only 5xx server errors are sent. This includes:

- All exceptions (except `HttpException` with 4xx status codes)
- `HttpException` with status codes 500-599

4xx client errors are intentionally ignored to reduce noise.

Advanced Usage
--------------

[](#advanced-usage)

### Multiple Environments

[](#multiple-environments)

```
'targets' => [
    [
        'class' => \Salikhov\TelegramLogTarget\TelegramTarget::class,
        'levels' => ['error'],
        'chat_id' => getenv('TELEGRAM_ERROR_CHAT_ID'),
        'bot_token' => getenv('TELEGRAM_BOT_TOKEN'),
        'title' => YII_ENV_PROD ? 'PROD Error' : 'DEV Error',
        'enabled' => YII_ENV_PROD, // Only enable in production
    ],
],
```

### Combine with File Logging

[](#combine-with-file-logging)

```
'targets' => [
    // File logging for all errors
    [
        'class' => 'yii\log\FileTarget',
        'levels' => ['error', 'warning'],
    ],
    // Telegram only for critical errors
    [
        'class' => \Salikhov\TelegramLogTarget\TelegramTarget::class,
        'levels' => ['error'],
        'chat_id' => getenv('TELEGRAM_ERROR_CHAT_ID'),
        'bot_token' => getenv('TELEGRAM_BOT_TOKEN'),
    ],
],
```

Requirements
------------

[](#requirements)

- PHP 8.0+
- Yii2 2.0+

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

yii2-telegram-log-target
========================

[](#yii2-telegram-log-target-1)

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance77

Regular maintenance activity

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

128d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fd0b9e39adb7fbfe6ba55a737b9fa27f5a7abb9dc54bc872513b960883789972?d=identicon)[Salikhov\_ID](/maintainers/Salikhov_ID)

---

Top Contributors

[![SalikhovID](https://avatars.githubusercontent.com/u/62024188?v=4)](https://github.com/SalikhovID "SalikhovID (1 commits)")

---

Tags

loggingmonitoringyii2telegramerror-notification

### Embed Badge

![Health badge](/badges/salikhov-yii2-telegram-log-target/health.svg)

```
[![Health](https://phpackages.com/badges/salikhov-yii2-telegram-log-target/health.svg)](https://phpackages.com/packages/salikhov-yii2-telegram-log-target)
```

###  Alternatives

[bedezign/yii2-audit

Yii2 Audit records and displays web/cli requests, database changes, php/js errors and associated data.

201657.4k4](/packages/bedezign-yii2-audit)[airani/yii2-telegram-log

Yii 2.0 telegram log target, send logs to the telegram chats or channels

1655.9k](/packages/airani-yii2-telegram-log)

PHPackages © 2026

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