hebrahimzadeh/laravel-mattermost-logger

1.5.0 2021-01-15 12:36 UTC

This package is auto-updated.

Last update: 2024-09-12 19:36:12 UTC


README

此驱动程序允许您将日志发送到您的Mattermost(开源Slack替代品)。它将发送异常堆栈跟踪和日志上下文(Laravel中logger函数的第二个参数)。

example.png

安装

composer require thibaud-dauce/laravel-mattermost-logger

配置

添加日志驱动程序

在您的config/logging.php中添加新驱动程序

'mattermost' => [
    'driver' => 'custom',
    'via' => ThibaudDauce\MattermostLogger\MattermostLogger::class,
    'webhook' => env('MATTERMOST_WEBHOOK'),
],

并在config/logging.php中更新您的堆栈

'stack' => [
    'driver' => 'stack',
    'channels' => ['single', 'mattermost'],
],

如果您在测试期间不想将日志发送到Mattermost,请勿忘记在本地和测试环境中添加LOG_CHANNEL=single

可用选项

您可以在config/logging.php中在drivervia键之后添加选项。所有选项及其默认值都在代码中https://gitlab.com/thibauddauce/laravel-mattermost-logger/blob/master/src/MattermostHandler.php#L14-22

  • webhook (无内容): Mattermost实例的webhook URL
  • channel (town-square): 将发送日志的频道slug
  • icon_url (无内容): Mattermost中显示的图标相对URL(包将使用url()辅助函数生成完整路径)
  • username (Laravel Logs): Mattermost中显示的用户名
  • level (INFO): 低于此级别的日志将不会发送到您的Mattermost实例(默认情况下,调试日志不会发送)
  • level_mention (ERROR): 高于此级别,Mattermost中的日志将变红,并且人们将收到ping
  • mentions ([@here]): 在日志高于level_mention时ping的人员数组
  • short_field_length (62): 上下文内容超过此值的将被放入Mattermost的长字段中(两列布局,见截图)
  • max_attachment_length (6000): 截断此值以下的内容(否则Mattermost将拒绝负载)

使用方法

logger()->info('Some message', [
    'context' => 'Some contex',
    'an_array_of_things' => ['foo', 'bar', 'baz'],
]);

// Or

throw new Exception('An exception occured');

待办事项

  • 添加队列HTTP请求的可能性