承接 arhx/telegram-log-channel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

arhx/telegram-log-channel

Composer 安装命令:

composer require arhx/telegram-log-channel

包简介

A simple Laravel package to send log messages to a Telegram chat.

README 文档

README

A simple Laravel package to send log messages to a Telegram chat.

Installation

You can install the package via composer:

composer require arhx/telegram-log-channel

The service provider will be automatically registered.

Configuration

  1. Add the necessary environment variables to your .env file:

    TELEGRAM_LOG_BOT_TOKEN=your_bot_token_here
    TELEGRAM_LOG_CHAT_ID=your_chat_id_here
    • TELEGRAM_LOG_BOT_TOKEN: Your Telegram bot's token.
    • TELEGRAM_LOG_CHAT_ID: The ID of the chat where logs should be sent.
    • TELEGRAM_LOG_LEVEL: (Optional) The minimum log level to be sent (defaults to error).
    • TELEGRAM_LOG_THROTTLE: (Optional) Number of seconds to suppress duplicate messages (defaults to 600 = 10 minutes). Set to 0 to disable throttling.
  2. (Optional) The package comes with a default configuration for the telegram log channel. If you need to customize it, you can add your own channel configuration to config/logging.php:

    'channels' => [
        // ... other channels
    
        'telegram' => [
            'driver' => 'telegram',
            'token' => env('TELEGRAM_LOG_BOT_TOKEN'),
            'chat_id' => env('TELEGRAM_LOG_CHAT_ID'),
            'level' => env('TELEGRAM_LOG_LEVEL', 'debug'), // Example of overriding the level
        ],
    ],

Usage

To receive Telegram notifications for your logs, add the telegram channel to your chosen logging stack in config/logging.php.

If the environment variables TELEGRAM_LOG_BOT_TOKEN and TELEGRAM_LOG_CHAT_ID are not set, the telegram channel will gracefully fallback to a NullHandler, meaning no logs will be sent to Telegram and the application will not crash.

For example, to add it to the default stack channel:

'stack' => [
    'driver' => 'stack',
    'channels' => ['daily', 'telegram'], // Add 'telegram' here
    'ignore_exceptions' => false,
],

Now, any log message that meets the configured level will be sent to your Telegram chat.

Spam Throttling (Duplicate Suppression)

To avoid flooding your chat with the same error over and over, the package throttles identical messages. After a message is sent, any identical message is suppressed for TELEGRAM_LOG_THROTTLE seconds (defaults to 600 = 10 minutes).

Two messages are considered identical when their level, message text, and source file:line match. Volatile data (request body, query params, timestamps) is intentionally excluded from the comparison so that genuinely repeated errors collapse into a single notification.

TELEGRAM_LOG_THROTTLE=600   # suppress duplicates for 10 minutes
TELEGRAM_LOG_THROTTLE=0     # disable throttling entirely

This relies on your application's configured cache store (Cache facade). If the cache is unavailable for any reason, the package fails open and the message is still sent.

Tip for Laravel 12: You might just need to update your .env file to include telegram in the logging stack:

LOG_STACK=daily,telegram

Queue Job Failure Logging

The package automatically sends a Telegram notification when a queued job fails. This feature is enabled by default and works out of the box with Laravel's queue system (Laravel 10, 11, 12).

To disable it, set the following in your .env:

TELEGRAM_LOG_QUEUE_FAILURES=false

Each failed job notification includes:

  • Job class name
  • Exception message
  • Queue connection name
  • Queue name

Note: The notification respects your configured TELEGRAM_LOG_LEVEL. Since failures are logged at the error level, make sure your level is set to error or lower (e.g., debug, info, warning, error).

Using config:cache

If you use php artisan config:cache (recommended in production), you must publish the package config so the env variable is captured at cache time:

php artisan vendor:publish --tag=telegram-log-channel-config

This creates config/telegram-log-channel.php in your application. The TELEGRAM_LOG_QUEUE_FAILURES env variable will then be read correctly even when the config cache is active.

Testing

In a Laravel Application

After installing the package in your Laravel app, you can test your configuration by running:

php artisan telegram-log:test

Note: This command sends a message with the error level. If your TELEGRAM_LOG_LEVEL is set to a higher level (e.g., emergency), the test message will not be sent.

During Package Development

If you are developing the package, you can run the command directly from the root:

  1. Copy .env.example (if available) to .env or create it manually with your bot token and chat ID.
  2. Run:
php artisan telegram-log:test

arhx/telegram-log-channel 适用场景与选型建议

arhx/telegram-log-channel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 115 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 arhx/telegram-log-channel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 arhx/telegram-log-channel 我们能提供哪些服务?
定制开发 / 二次开发

基于 arhx/telegram-log-channel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2026-01-21