marekmiklusek/telegram-logger
Composer 安装命令:
composer require marekmiklusek/telegram-logger
包简介
A Laravel package to send logs to Telegram.
README 文档
README
📢 Laravel Telegram Logger
🚀 Laravel Telegram Logger is a package that sends Laravel log messages and exceptions to Telegram for real-time monitoring.
📌 Features
✅ Real-time logging to Telegram
✅ Supports all log levels (debug, info, warning, error, etc.)
✅ Automatic exception handling (captures error file, line, and message)
✅ Configurable log level filtering
✅ Silent notifications support (to avoid sound/vibration in Telegram)
✅ Minimal setup, easy to integrate
✅ Can be enabled/disabled via configuration
🛠 Installation
Require the package via Composer:
composer require marekmiklusek/telegram-logger
🔧 Configuration
Publish the package configuration:
php artisan vendor:publish --tag=telegram-logger-config
This will create a config file at config/telegram-logger.php.
.env Configuration
Add your Telegram Bot API token and Chat ID to your .env file:
TELEGRAM_BOT_TOKEN=your_bot_token TELEGRAM_CHAT_ID=your_chat_id
Config File (config/telegram-logger.php)
return [ 'bot_token' => env('TELEGRAM_BOT_TOKEN'), 'chat_id' => env('TELEGRAM_CHAT_ID'), 'level' => 'error', 'silent_notification' => false, 'is_enabled' => true, ];
🏗 Usage
Basic Logging
Use Laravel's Log facade as usual, and errors will be sent to Telegram automatically:
use Illuminate\Support\Facades\Log; Log::debug('Debug message'); Log::info('Info message'); Log::warning('Warning message'); Log::error('Error message');
Logging with Context
You can pass additional context to logs:
Log::error('User not found', ['user_id' => 42, 'action' => 'login']);
Logging Exceptions
Exceptions are automatically detected and logged:
try { throw new \Exception('Database connection failed!'); } catch (\Exception $exception) { Log::error('Unhandled exception occurred', ['exception' => $exception]); }
⚙ How It Works
The package listens to Laravel's logging events and sends structured messages to Telegram.
Example Telegram Log Output
🛠️ Application: MyLaravelApp
🌍 Environment: production
❌ Level: ERROR
📝 Message: "User not found"
📌 File:
/var/www/html/app/Http/Controllers/UserController.php:45
📂 Context:
{
"user_id": 42,
"action": "login"
}
⏳ Time: 2025-02-19 10:15:30
Example Telegram Log Output (Exception)
🛠️ Application: MyLaravelApp
🌍 Environment: production
❌ Level: ERROR
🔥 Exception Occurred !
💥 Message: "Database connection failed!"
📌 File:
/var/www/html/app/Services/DatabaseService.php:30
⏳ Time: 2025-02-19 10:18:45
🎯 Advanced Configuration
1️⃣ Logger Enablement
You can enable or disable the logger in config/telegram-logger.php:
return [ 'is_enabled' => false, ];
✅ If true, logs will be sent to Telegram as configured
✅ If false, the logger will be completely disabled (no logs sent)
2️⃣ Log Level Filtering
You can define the minimum log level in config/telegram-logger.php:
return [ 'level' => 'warning', ];
debug: Logs everythinginfo: Logsinfo,notice,warning,error,critical,alert,emergencyerror: Logserror,critical,alert,emergencycritical: Logs onlycritical,alert,emergency
3️⃣ Silent Notifications
Enable silent notifications (no sound/vibration) in config/telegram-logger.php
return [ 'silent_notification' => true, ];
✅ If true, messages will be sent silently.
✅ If false, Telegram will send notifications normally.
💡 Troubleshooting
❓ Logs not appearing in Telegram?
- Check that your
.envvalues are correctly set:
php artisan config:clear php artisan config:cache
- Ensure your bot has permission to send messages to your chat.
❓ Getting "Chat not found" error?
- Make sure you have sent a message to your bot first.
- Use this tool to get your Chat ID.
📜 License
This package is open-source and licensed under the MIT License.
marekmiklusek/telegram-logger 适用场景与选型建议
marekmiklusek/telegram-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 714 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「php」 「logger」 「laravel」 「telegram」 「laravel-telegram-logger」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 marekmiklusek/telegram-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marekmiklusek/telegram-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 marekmiklusek/telegram-logger 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Workflow logger
HTTP request logger middleware for Laravel
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
Simple ASCII output of array data
Logging http requests and errors
统计信息
- 总下载量: 714
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-19