定制 congnv/monolog-telegram-handler 二次开发

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

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

congnv/monolog-telegram-handler

最新稳定版本:1.0.3

Composer 安装命令:

composer require congnv/monolog-telegram-handler

包简介

Telegram Handler for Monolog.

README 文档

README

Telegram handler for Monolog.

Install

composer require congnv/monolog-telegram-handler

Declaring handler object

To declare this handler, you need to know the bot token and the chat identifier(chat_id) to which the log will be sent.

$handler = new \TelegramLog\TelegramHandler('<token>', '<chat_id>');

Using with Laravel

Add telegram channel to config/logging.php

'telegram' => [
    'driver'  => 'custom',
    'via' => \TelegramLog\TelegramLogger::class,
    'level' => env('LOG_LEVEL', 'debug'),
    'bot_token' => env('TELEGRAM_BOT_TOKEN'),
    'chat_id' => env('TELEGRAM_CHAT_ID'),
    // 'max_stack_line' => 10,
],

Custom message formatter

Create new class implements \TelegramLog\TelegramMessageFormatterInterface

Example

<?php

namespace App\Logging\Formatter;

use Monolog\LogRecord;
use TelegramLog\TelegramMessageFormatterInterface;

class TelegramMessageFormatter implements TelegramMessageFormatterInterface
{
    public function format(LogRecord $record, int $maxStackLine): string
    {
        return [{$record->datetime->format('Y-m-d H:i:s')}] {$record->message}";
    }
}

Modify telegram channel

'telegram' => [
    'driver'  => 'custom',
    'via' => \TelegramLog\TelegramLogger::class,
    'formatter' => \App\Logging\Formatter\TelegramMessageFormatter::class,
    'level' => env('LOG_LEVEL', 'debug'),
    'bot_token' => env('TELEGRAM_BOT_TOKEN'),
    'chat_id' => env('TELEGRAM_CHAT_ID'),
    // 'max_stack_line' => 10,
],

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-03