muhamadhhassan/laramost

此包包含用于在 Laravel 日志通道中使用 Mattermost 的 Monolog 处理器和格式化工具

v1.1.0 2022-09-26 21:55 UTC

This package is auto-updated.

Last update: 2024-09-27 02:16:51 UTC


README

Laramost 是一个 Monolog 处理器通道,允许您将日志记录发送到 Mattermost 通道。

安装

$ composer require muhamadhhassan/laramost

日志级别

Monolog 日志级别用于设置消息颜色和图标

使用方法

在 Laravel 应用中

在您的 config/logging.php 文件中,将 mattermost 通道添加到 channels 数组

use LaraMost\Formatter\MattermostFormatter;
use LaraMost\Handler\MattermostWebhookHandler;

'channels' => [
    'mattermost' => [
        'driver'  => 'monolog',
        'handler' => MattermostWebhookHandler::class,
        'formatter' => MattermostFormatter::class,
        'with' => [
            'hook' => 'https://your-mattermost.com/hooks/xxx-generatedkey-xxx',
        ],
        'level' => 'error'
    ],
],

然后,简单地使用 Laravel Log 门面

Log::channel('mattermost')->error('Something went wrong', ['user_id' => 5]);

在任意 PHP 应用中

use Monolog\Logger;
use LaraMost\Formatter\MattermostFormatter;
use LaraMost\Handler\MattermostWebhookHandler;

$logger = new Logger('application');
$handler = new MattermostWebhookHandler('https://your-mattermost.com/hooks/xxx-generatedkey-xxx', Logger::ERROR);
$handler->setFormatter(new MattermostFormatter())
$logger->pushHandler($handler);

$logger->error('Something went wrong', ['user_id' => 5]);

两者都将发送以下消息到您的 Mattermost 通道: error-message.png

警告:当您将日志记录到 mattermost 通道时,请确保日志级别大于或等于在 config/logging.php 中定义的级别。