cytec/zend-log-slack 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

cytec/zend-log-slack

最新稳定版本:3.1.0

Composer 安装命令:

composer require cytec/zend-log-slack

包简介

Write laminas-log messages to a slack channel

README 文档

README

Write laminas-log messages to a slack channel

Installation

composer require cytec/laminas-log-slack

Slack Configuration

The log writer works by sending information to a "Incoming WebHooks" integration in Slack:

  1. Open the channel you would like to receive your log in.
  2. Click on the channel name in the top left corner and from the drop down menu select "Add an app or integration"
  3. Click "Build" (top right)
  4. Click "Make a custom integration"
  5. Choose "Incoming WebHooks"
  6. Click the large green "Add Incoming WebHooks integration"

You'll need the Webhook URL to configure the writer. Under "Integration Settings" you can customize some defaults.

Usage

Manual

$writer = new \Cytec\Log\Writer\Slack('<YOUR_SLACK_WEBHOOK_URL>');

//Optional - use this filter only if you want to send critical messages to Slack
$writer->addFilter(new \Laminas\Log\Filter\Priority(\Laminas\Log\Logger::CRIT));

$logger = new \Laminas\Log\Logger();
$logger->addWriter($writer);

$logger->info('Informational message');
$logger->crit('Critical message');

//second "extra" parameter is supported and printed as properties in slack
$logger->crit('Critical message', $_SERVER);

Via Service manager

Somewhere in your configuration (eg. config/autoload/global.php) add

...
'log' => [
    'SlackLog' => [
        'writers' => [
            'default' => [
                'name' => 'Cytec\Log\Writer\Slack',
                'options' => [
                    'webhook_url' => '<YOUR_SLACK_WEBHOOK_URL>',
                    'bot_name' => 'Project Name',   //optional
                    'channel_override' => '#alerts',//optional @person is also supported
                    'filters' => \Laminas\Log\Logger::CRIT,      //optional - filter by priority
                ]
            ]
        ]
    ]
],
...

And then you can get the logger via the service manager:

$log = $this->getServiceManager()->get('SlackLog');
$log->crit('Critical message');

Keep in mind

This writer isn't suitable for constant writing due to the fact that log messages are sent via http interface to the Slack api. This makes it very slow and can add significant delay in application response times. The intended use is for critical or very high priority messages that need the immediate attention of a real person.

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2017-01-30