2017 © Pedro Peláez
 

library zend-log-slack

Write zend-log messages to a slack channel

image

cytec/zend-log-slack

Write zend-log messages to a slack channel

  • Tuesday, May 2, 2017
  • by ptodorov
  • Repository
  • 4 Watchers
  • 5 Stars
  • 391 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 20 % Grown

The README.md

laminas-log-slack

Write laminas-log messages to a slack channel, (*1)

Installation

composer require cytec/laminas-log-slack

Slack Configuration

The log writer works by sending information to a "Incoming WebHooks" integration in Slack:, (*2)

  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., (*3)

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, (*4)

...
'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:, (*5)

$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., (*6)

The Versions

02/05 2017

dev-master

9999999-dev https://github.com/cytecbg/zend-log-slack

Write zend-log messages to a slack channel

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

log logging zf2 writer zf3 slack

30/01 2017

1.0.1

1.0.1.0 https://github.com/cytecbg/zend-log-slack

Write zend-log messages to a slack channel

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

log logging zf2 writer zf3 slack

30/01 2017

v1.0.0

1.0.0.0 https://github.com/cytecbg/zend-log-slack

Write zend-log messages to a slack channel

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

log logging zf2 writer zf3 slack