prog-time/tg-logger
Composer 安装命令:
composer require prog-time/tg-logger
包简介
A Laravel package for sending logs to Telegram
README 文档
README
A module for Laravel that allows you to send logs to Telegram.
Description
This module allows you to send logs to a Telegram group, breaking them down by topic. You can describe the configuration for the basic log types or write your own logging levels.
Installing the module
The installation is done using Composer:
composer require prog-time/tg-logger
Configuring the module
- Create a Telegram bot
- Create a Telegram group and include "Topics" in it
- Specify the variables in .environment
TG_LOGGER_TOKEN="token_bot" TG_LOGGER_CHAT_ID="id_group"
- Add the created bot and grant it administrator rights
- Create a configuration file config/tg-logger.php manually or using a command.
php artisan vendor:publish --tag=config
- In config/tg-logger.php specify the bot token, the ID of the created group, and describe the topics that need to be created.
return [ 'token' => env('TG_LOGGER_TOKEN'), 'chat_id' => env('TG_LOGGER_CHAT_ID'), 'topics' => [ [ 'name' => 'Debug messages', 'icon_color' => '9367192', 'level' => 'debug', ], [ 'name' => 'Cron tasks', 'icon_color' => '9367192', 'level' => 'crone', ], [ 'name' => 'Errors', 'icon_color' => '9367192', 'level' => 'error, notice, warning, emergency', ] ] ];
- Run the command to create themes in a group. After executing this command, the file config/tg-logger.php it will be overwritten and the topic IDs for each log type will be indicated in it.
php artisan tglogger:create-topics
Sending any type of error
To catch all types of errors, you need to change the basic log handler in the configuration file config/logging.php by specifying the module classes as handlers.
'channels' => [
...
'telegram' => [
'driver' => 'monolog',
'handler' => ProgTime\TgLogger\TgHandler::class,
'formatter' => ProgTime\TgLogger\TgFormatter::class,
'level' => 'debug',
],
...
],
and in .env, change the LOG_CHANNEL parameter
LOG_CHANNEL=telegram
Calling the module operation directly
To work with the module directly, you can use the following code.
TgLogger::sendLog('Your message', 'level');
prog-time/tg-logger 适用场景与选型建议
prog-time/tg-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.97k 次下载、GitHub Stars 达 23, 最近一次更新时间为 2024 年 12 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 prog-time/tg-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 prog-time/tg-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 23
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-13