salikhov/yii2-telegram-log-target
Composer 安装命令:
composer require salikhov/yii2-telegram-log-target
包简介
Yii2 log target that sends error notifications to Telegram
README 文档
README
A Yii2 log target that sends error notifications to Telegram. Perfect for real-time error monitoring of your Yii2 applications.
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
composer require salikhov/yii2-telegram-log-target
Configuration
1. Create a Telegram Bot
- Open Telegram and search for @BotFather
- Send
/newbotand follow the instructions - Copy the bot token (looks like
123456789:ABCdefGHIjklMNOpqrsTUVwxyz)
2. Get Your Chat ID
- Start a chat with your bot
- Send any message to the bot
- Visit
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Find your
chat_idin the response
For group chats, add the bot to the group and use the negative group ID.
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
Add to your .env file:
TELEGRAM_ERROR_CHAT_ID=123456789 TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
chat_id |
string | null | Telegram chat ID (user, group, or channel) |
bot_token |
string | null | Telegram bot token from @BotFather |
title |
string | "Error" | Title prefix shown in bold at the top |
levels |
array | - | Standard Yii2 log levels to capture |
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
By default, only 5xx server errors are sent. This includes:
- All exceptions (except
HttpExceptionwith 4xx status codes) HttpExceptionwith status codes 500-599
4xx client errors are intentionally ignored to reduce noise.
Advanced Usage
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
'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
- PHP 8.0+
- Yii2 2.0+
License
MIT License. See LICENSE for details.
yii2-telegram-log-target
salikhov/yii2-telegram-log-target 适用场景与选型建议
salikhov/yii2-telegram-log-target 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「monitoring」 「yii2」 「telegram」 「error-notification」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 salikhov/yii2-telegram-log-target 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 salikhov/yii2-telegram-log-target 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 salikhov/yii2-telegram-log-target 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
A custom URL rule class for Yii 2 which allows to create translated URL rules
A Zend Framework module that sets up Monolog for logging in applications.
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Statsd (Object Oriented) client library for PHP
统计信息
- 总下载量: 34
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-05