raifucore/laravel-telegram-logger
Composer 安装命令:
composer require raifucore/laravel-telegram-logger
包简介
Send logs to Telegram
README 文档
README
Send Laravel logs to Telegram chat via Telegram Bot API.
Install
composer require raifucore/laravel-telegram-logger
Publish package config and views:
php artisan vendor:publish --provider="RaifuCore\TelegramLogger\ServiceProvider"
Configure environment
Add these variables to your .env:
TELEGRAM_LOGGER_ENABLE=true TELEGRAM_LOGGER_BOT_TOKEN=7123456789:ABHo3qcH6G1wMi4VPc8xxZZ474UizrF5e6Dk TELEGRAM_LOGGER_CHAT_ID=-1112223334445 TELEGRAM_LOGGER_MESSAGE_THREAD_ID= TELEGRAM_LOGGER_QUEUE=default TELEGRAM_LOGGER_QUEUE_CONNECTION=sync TELEGRAM_LOGGER_TIMEOUT=5 # optional TELEGRAM_LOGGER_PROXY=
Variables
TELEGRAM_LOGGER_ENABLE: enable or disable telegram logging.TELEGRAM_LOGGER_BOT_TOKEN: Telegram bot token from@BotFather.TELEGRAM_LOGGER_CHAT_ID: target chat id.TELEGRAM_LOGGER_MESSAGE_THREAD_ID: optional topic id for forum chats.TELEGRAM_LOGGER_QUEUE: queue name for log delivery jobs.TELEGRAM_LOGGER_QUEUE_CONNECTION: queue connection (sync,redis, etc.).TELEGRAM_LOGGER_TIMEOUT: HTTP timeout (seconds) for Telegram API calls.TELEGRAM_LOGGER_PROXY: optional proxy URL, for example:tcp://host:porttcp://user:pass@host:portsocks5://user:pass@host:port
Configure config/logging.php
Add a custom channel:
'telegram' => [ 'driver' => 'custom', 'via' => \RaifuCore\TelegramLogger\Logger::class, 'level' => 'debug', ],
If your default channel is stack, add telegram there:
'stack' => [ 'driver' => 'stack', 'channels' => ['single', 'telegram'], ],
Or set default channel:
LOG_CHANNEL=telegram
Usage
Use Laravel Log as usual:
use Illuminate\Support\Facades\Log; Log::error('Payment failed', ['order_id' => 123]); Log::channel('telegram')->warning('Telegram channel only');
Queue behavior
Messages are dispatched as jobs (RaifuCore\TelegramLogger\Job).
- With
TELEGRAM_LOGGER_QUEUE_CONNECTION=sync, jobs are executed immediately. - With async connections (for example
redis), jobs are pushed to queue workers.
Templates
By default package uses Blade template:
'template' => 'telegram_logger::standard',
To customize templates:
- Publish package views.
- Create your own template in
resources/views/vendor/telegram_logger/. - Set
templateinconfig/telegram_logger.phpor at runtime:
config(['telegram_logger.template' => 'telegram_logger::minimal']);
Per-level overrides
You can override parameters per log level in config/telegram_logger.php:
'levels' => [ 'error' => [ 'chat_id' => env('TELEGRAM_LOGGER_ERROR_CHAT_ID'), 'options' => [ 'disable_notification' => true, ], ], ],
Supported keys per level:
tokenchat_idmessage_thread_idtemplateoptions
Create Telegram bot
- Open
@BotFather. - Run
/newbot. - Configure bot name and username.
- Copy token to
.env. - Open your bot and send
/start.
raifucore/laravel-telegram-logger 适用场景与选型建议
raifucore/laravel-telegram-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 239 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 raifucore/laravel-telegram-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 raifucore/laravel-telegram-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 239
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-01