承接 jacklul/monolog-telegram 相关项目开发

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

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

jacklul/monolog-telegram

Composer 安装命令:

composer require jacklul/monolog-telegram

包简介

Monolog handler that sends logs through Telegram bot to any chat in HTML format

README 文档

README

Send your logs through Telegram bot to any chat and make them look fancy!

Features:

  • Continous logging and batch logging support
  • Standard stack traces wrapped in <code></code> tags
  • Automatic splitting of the message when it exceeds maximum limit

Prerequisites

  • Telegram Bot API token - see here to learn how to obtain one
  • ID of the chat to which you want to send the logs - see below

Obtaining chat ID

One of the simplest ways to do that is to interact with the bot in the target chat:

  • private and group chats - send any dummy command
  • channels - post something in it

After interacting visit https://api.telegram.org/botTOKEN/getUpdates (replace TOKEN with your actual bot token), you will be able to find the chat id (chat_id) in the result JSON.

Installation

Install with Composer:

$ composer require jacklul/monolog-telegram

Usage

To use this handler you just have to add it like every other Monolog handler:

require 'vendor/autoload.php';

$logger = new Logger('My project');
$handler = new TelegramHandler(
    '123456789:teMbvbETojnSG93jDhnynvH8pT28H9TIB1h',  // Bot API token
    987654321,  // Target Chat ID
    Logger::ERROR,  // Log level, default: DEBUG
    true,  // Bubble up the stack or not, default: true
    true,  // Use cURL or not? default: true = use when available
    10,    // Timeout for API requests, default: 10
    true   // Verify SSL certificate or not? default: true, false only useful for development - avoid in production
    2,     // (optional) Target Thread ID for group chats with Topics enabled
);

$handler->setFormatter(new TelegramFormatter());    // Usage of this formatter is optional but recommended if you want better message layout
$logger->pushHandler($handler);

$logger->error('Error!');

To prevent spamming the chat and hitting Telegram's API limits it is advised to use DeduplicationHandler and/or BufferHandler, ideal solution for production use would be:

$handler = new TelegramHandler('TOKEN', 123456789);
$handler->setFormatter(new TelegramFormatter());

// Combine all log entries into one and force batch processing
$handler = new BufferHandler($handler);

// Make sure that particular log stack wasn't sent before
$handler = new DeduplicationHandler($handler);

// Keep collecting logs until ERROR occurs, after that send collected logs to $handler
$handler = new FingersCrossedHandler($handler, new ErrorLevelActivationStrategy(Logger::ERROR));

$logger->pushHandler($handler);

You can customize the formatter:

$html = true;    // Choose whether to send the message in HTMl format
$format = "%emoji% <b>%level_name%</b> (%channel%) [%date%]\n\n%message%\n\n%context%%extra%";   // EMOJI ERROR (My project) [2018-05-01 15:55:15 UTC]
$date_format = 'Y-m-d H:i:s e';       // 2018-05-01 15:55:15 UTC, format must be supported by DateTime::format
$separator = '-';       // Seperation character for batch processing - when empty one empty line is used
$emojis = [         // Override any level emoji
    'NOTICE' => '🤖'
];

$handler->setFormatter(new TelegramFormatter($html, $format, $date_format, $separator, $emojis));

Running tests

Create .env file:

TELEGRAM_TOKEN=BOT_TOKEN
TELEGRAM_CHAT_ID=CHAT_ID_THE_BOT_WILL_SPAM;

Run composer check-code and composer test.

License

See LICENSE.

jacklul/monolog-telegram 适用场景与选型建议

jacklul/monolog-telegram 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 70.33k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2018 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「log」 「logging」 「monolog」 「bot」 「telegram」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 24
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-02-22