Skip to content
Utilizes Laravel's notifications to provide logging to slack at various levels. Inspired by Log4j.
Branch: master
Clone or download
cr0wst Travis will now run phpunit after phpcs. (#7)
* Travis will now run phpunit after phpcs.
* Updated tests to use Orchestra\Testbench to avoid extra dependencies on laravel framework.

Additional fixes discovered thanks to testing:
* Removed void return type for 7.0 compatability.
Latest commit 0a13c5b Jan 15, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json
example.png
phpunit.xml

README.md

Laravel Slack Log

Latest Stable Version Latest Unstable Version Total Downloads Build Status

This package utilizes Laravel's native ability to create slack notifications to log at different log levels. This was inspired by Log4j.

Log Levels

There are several different log levels that can be used. The desired level of logging is defined in the config.

Here are some example uses of the different log levels:

  • ERROR - Indicates that an error occured.
  • WARN - Indicates that an error occured but it was recoverable.
  • INFO - Informational message usually explaining something in a business rule sense.
  • TRACE - Used for reporting where, in the code, the execution is taking place. Could report entering and leaving functions.
  • DEBUG - Used for dumping the contents of a variable.

Each message is implemented in the same way. The log levels are for you, the developer, to decide how to use.

The configured log level is checked before the message is sent. Levels are inclusive in that a specific level will include all message levels above it. For example, INFO will include INFO, WARN, and ERROR.

In some cases, it can be non-trivial to generate the message string. Logging guards have been provided to assist with this.

Installation Steps

Install Through Composer

composer require smcrow/laravel-slack-log

Register the Service Provider

Laravel 5.5

Laravel 5.5 allows for the auto-discovery of service providers. The SlackLogServiceProvider will automatically be discovered.

Pre Laravel 5.5

You'll need to register the command in order for it to be usable. Modify the register method of AppServiceProvider:

public function register()
{
    $this->app->register(SlackLogServiceProvider::class);
}

Registering the Facade

You can register the optional facade by adding the following to your app.php aliases:

'SlackLog' => \Smcrow\SlackLog\Facades\SlackLog::class

Configuration

Use php artisan vendor:publish to create a new configuration file. The file will be config/slack-log.php.

In this file you will need to provide the webhook url. I recommend reading Slack Incoming Webhooks for more information on how to setup the webhook.

Example Usage

With logging guards and using the facade:

$user = ['name' => 'John', 'age' => 65];

if (SlackLog::isDebugEnabled()) {
    SlackLog::debug('User: ' . print_r($user, true));
}

Produces the following:

Debug Example

Feedback and Contributions

Please feel free to offer suggestions by submitting an Issue. Alternatively, submit a pull request with any features you wish to add. This is a work-in-progress, and I would welcome any and all feedback.

You can’t perform that action at this time.