dopiaza/slack-exception-logger-bundle

Log symfony2 exceptions to a Slack channel

2.0 2017-08-11 15:43 UTC

This package is not auto-updated.

Last update: 2024-05-24 20:15:05 UTC


README

#Slack Exception Logger Bundle for Symfony2

This bundle allows exceptions thrown in a symfony2 app to be logged automatically to a Slack channel.

Alt text

To use, you first need to set up an incoming webhook in Slack - you can do this at https://your_slack_instance.slack.com/services/new/incoming-webhook (replace your_slack_instance with whatever your particular Slack instance is called). Once you've done that, you'll be given a web hook URL - make a note of that, you'll need to add that to your config.yml file.

Install this bundle into your symfony app:

$ composer require dopiaza/slack-exception-logger-bundle

Next, add the bundle to registerBundles in AppKernel.php:

new Dopiaza\Slack\ExceptionLoggerBundle\DopiazaSlackExceptionLoggerBundle(),
            

And then set up your config.yml:

dopiaza_slack_exception_logger:
    webhook: https://hooks.slack.com/services/T0000000/B000000000/000000000000000000
    botname: symfony-bot
    name: My Symfony Application
    environments:
        test:
            enabled: true
            color: '#992255'
            channel: symfony-exceptions
        prod:
            channel: symfony-exceptions
            exclude_exception:
                - Symfony\Component\HttpKernel\Exception\NotFoundHttpException

webhook is the URL of the incoming web hook for your Slack instance.

botname is the name of the user that message will be posted as in your Slack channel. It has no default value. If no value is specified, Slack will use the name specified in your incoming web hook integration.

name is the name of your symfony application. This is useful if you have multiple apps all posting to the same channel.

environments holds all environment-specific configuration settings. Usual environment values to include in here would be dev, test and prod. If the environment being used isn't listed in this section, no exceptions will be posted. You probably don't really want to list dev in here, as that one is likely to generate quite a bit of noise, but hey, it's your choice.

enabled is an optional boolean to allow logging to be enabled or disabled on a per-channel basis. If not specified, it defaults to true.

color is an optional field used to determine the colour of the sidebar for the message. Valid values are good (green), warning (yellow), danger (red), or any hex value (e.g. '#abcdef'). Note that if you use a hex value, be sure to put it in quotes, otherwise the # will be interpreted as the start of a comment and the sidebar will come out an unattractive grey colour. If not specified, the default value is danger.

channel is the name of the channel to which exceptions are posted.

exclude_exception is an optional array of Exception class names which should be ignored. A typical use for this would be avoid a plethora of 'Not Found' exceptions being displayed for a production server that's publicly visible and thus subject to people randomly probing it.