定制 scratcher28/tg-logger 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

scratcher28/tg-logger

Composer 安装命令:

composer require scratcher28/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

  1. Create a Telegram bot
  2. Create a Telegram group and include "Topics" in it
  3. Specify the variables in .environment
TG_LOGGER_TOKEN="token_bot"
TG_LOGGER_CHAT_ID="id_group"
  1. Add the created bot and grant it administrator rights
  2. Create a configuration file config/tg-logger.php manually or using a command.
php artisan vendor:publish --tag=config
  1. 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',
        ]
  ]
];
  1. 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');

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-17