milly / laralog

PHP 包,用于通过 Telegram 机器人处理日志

1.0.3 2024-03-29 12:34 UTC

This package is auto-updated.

Last update: 2024-09-29 13:37:35 UTC


README

PHP Laravel 包,通过 Telegram 机器人进行调试和处理日志

License Packagist Version Packagist Version

要求

安装

使用 composer 安装包

composer require milly/laralog

发布配置文件

 php artisan vendor:publish --tag=laralog-config

将以下环境变量添加到您的 .env 文件中,或在 config/laralog.php 文件中设置它们

TELEGRAM_BOT_TOKEN=1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZ
TELEGRAM_CHAT_ID=-1234567890

方法

该包提供了以下方法将日志消息发送到 Telegram 机器人

  • Laralog::debug(int|string|array|object $message)
  • Laralog::info(int|string|array|object $message)
  • Laralog::warning(int|string|array|object $message)
  • Laralog::error(int|string|array|object $message)

用法

将日志消息发送到 Telegram 机器人

use Milly\Laralog\Laralog;

// call statically
Laralog::debug('This is a debug message');

//call instance
$laralog = new Laralog();
$laralog->info('This is an info message');

您将在 Telegram 机器人中收到消息,其中包含调试消息,如下所示:

开发模式

默认情况下,该包处于开发模式,这意味着只有当 APP_ENV 设置为 local 时才会发送消息。如果您想在生产模式下发送消息,需要将 config/laralog.php 文件中的 is_enabled 键设置为 true

return [
    'is_enabled' => true,
    'telegram_bot_token' => env('TELEGRAM_BOT_TOKEN'),
    'telegram_chat_id' => env('TELEGRAM_CHAT_ID'),
];

许可证

此软件包是开源软件,受 MIT 许可证 的许可。