rahimi/monolog-telegram

Monolog 处理器,用于将消息发送到 Telegram 频道

此软件包的官方仓库似乎已消失,因此软件包已被冻结。

v1.0.7 2020-10-22 17:10 UTC

This package is auto-updated.

Last update: 2024-07-16 15:19:00 UTC


README

为 php monolog 提供的 Telegram 处理器,允许您通过机器人将消息记录到 Telegram 频道。

Latest Stable Version Total Downloads License

截图

telegram handler demo screenshot

安装

使用 composer 安装

composer require rahimi/monolog-telegram  

用法

它就像其他 monolog 处理器一样,您需要将以下参数传递给 TelegramHandler 对象

  • $token 由 BotFather 提供的您的机器人令牌
  • $channel 您的 Telegram 频道的 userName
  • $date_default_timezone_set时区标识符,如 'UTC' 或 'Europe/Lisbon',将用作所有日期/时间函数的 默认时区(可选,默认值 'UTC'
  • $dateFormat 传递日期格式(可选,默认值 'Y-m-d H:i:s'
  • $timeOut 发送日志消息时连接到 Telegram 服务器的超时值(以秒为单位)(可选,默认值 100)。使用 0 以无限期等待。

示例

现在可以简单地像这样使用

require 'vendor/autoload.php';
use Monolog\Logger;
use rahimi\TelegramHandler\TelegramHandler;
$log = new Logger('TelegramHandler');
$log->pushHandler(new TelegramHandler($token,$channel,'UTC','F j, Y, g:i a',60));


$log->info('hello world !');
/**
* There is 8 level of logging
*/
$log->notice('hello world !');
$log->info('hello world !');
$log->debug('hello world !');
$log->warning('hello world !');
$log->critical('hello world !');
$log->alert('hello world !');
$log->emergency('hello world !');
$log->error('hello world !');


/**
* Optionally you can pass second paramater such as a object
**/
$log->info('user just logged in !',['user'=>$user]);

许可证

本工具遵循 MIT 许可证,因此请随意将其分叉并使其变得更好!