├── composer.json ├── LICENSE ├── src ├── config │ └── config.php └── Rap2hpoutre │ └── LaravelEpilog │ └── LaravelEpilogServiceProvider.php └── README.md /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rap2hpoutre/laravel-epilog", 3 | "description": "More info in laravel's log", 4 | "license": "MIT", 5 | "keywords": ["log", "laravel", "logging"], 6 | "authors": [ 7 | { 8 | "name": "rap2hpoutre", 9 | "email": "raphael@ornikar.com" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=5.4.0", 14 | "illuminate/support": "5.*" 15 | }, 16 | "autoload": { 17 | "psr-0": { 18 | "Rap2hpoutre\\LaravelEpilog\\": "src/" 19 | } 20 | }, 21 | "minimum-stability": "stable" 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 raph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /src/config/config.php: -------------------------------------------------------------------------------- 1 | [ 16 | /** 17 | * Your slack token. 18 | * 19 | * Go to the authorization page (https://api.slack.com/web#auth) and 20 | * generate a new token 21 | */ 22 | 'token' => 'your-token', 23 | 24 | /** 25 | * Slack channel (encoded ID or name) 26 | * 27 | * Send the message to an existing '#channel' or 'private-group' 28 | */ 29 | 'channel' => '#general', 30 | 31 | /** 32 | * The name of the bot 33 | */ 34 | 'username' => 'Error Bot', 35 | 36 | /** 37 | * Slack notification triggers on this environment 38 | * 39 | * String or array. Empty array means disabled. 40 | */ 41 | 'env' => 'production' 42 | ] 43 | ]; 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Epilog for Laravel 5 2 | [![Packagist](https://img.shields.io/packagist/l/rap2hpoutre/laravel-epilog.svg)](https://packagist.org/packages/rap2hpoutre/laravel-epilog) [![Packagist](https://img.shields.io/packagist/v/rap2hpoutre/laravel-epilog.svg)](https://packagist.org/packages/rap2hpoutre/laravel-epilog) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/rap2hpoutre/laravel-epilog/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/rap2hpoutre/laravel-epilog/?branch=master) [![Build Status](https://scrutinizer-ci.com/g/rap2hpoutre/laravel-epilog/badges/build.png?b=master)](https://scrutinizer-ci.com/g/rap2hpoutre/laravel-epilog/build-status/master) [![SensioLabs Insight](https://insight.sensiolabs.com/projects/ad260efc-ca58-4521-9999-daadf92706d5/mini.png)]() 3 | ## What? 4 | 5 | Power up logs. Add client context (IP, referer, user ID and more). Notify on slack on production error. 6 | 7 | ![test](https://cloud.githubusercontent.com/assets/1575946/9824692/caeda282-58ce-11e5-9c57-3f186df57a7b.png) 8 | 9 | ## Install 10 | 11 | Install via composer 12 | ``` 13 | composer require rap2hpoutre/laravel-epilog 14 | ``` 15 | 16 | Add Service Provider to `config/app.php` in `providers` section 17 | ```php 18 | Rap2hpoutre\LaravelEpilog\LaravelEpilogServiceProvider::class, 19 | ``` 20 | 21 | (optional) Publish configuration in order to use Slack alerts 22 | ```php 23 | php artisan vendor:publish 24 | ``` 25 | 26 | Call `Log::info('hello world')` or whatever you want and go to see your logs. 27 | -------------------------------------------------------------------------------- /src/Rap2hpoutre/LaravelEpilog/LaravelEpilogServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes(array( 17 | __DIR__ . '/../../config/config.php' => config_path('epilog.php') 18 | )); 19 | 20 | $logger = \Log::getMonolog(); 21 | 22 | // Additional info in message 23 | $logger->pushProcessor(function($record) { 24 | $info = ''; 25 | if (\Auth::check()) { 26 | $info .= 'User #' . \Auth::user()->id . ' (' . \Auth::user()->email . ') - '; 27 | } 28 | if (isset($_SERVER['REMOTE_ADDR'])) { 29 | $info .= 'IP: ' . $_SERVER['REMOTE_ADDR']; 30 | } 31 | if (isset($_SERVER['REQUEST_URI'])) { 32 | $info .= "\n" . $_SERVER['REQUEST_METHOD'] . " " . url($_SERVER['REQUEST_URI']); 33 | } 34 | if (isset($_SERVER['HTTP_REFERER'])) { 35 | $info .= "\nReferer: " . $_SERVER['HTTP_REFERER']; 36 | } 37 | if ($info) { 38 | $info = "\n---\n$info\n---"; 39 | if (strpos($record['message'], "\n")) { 40 | $record['message'] = preg_replace("/\n/", $info . "\n", $record['message'], 1); 41 | } else { 42 | $record['message'] .= $info . "\n"; 43 | } 44 | } 45 | return $record; 46 | }); 47 | 48 | // Slack notification 49 | if (app()->environment(config('epilog.slack.env'))) { 50 | $slackHandler = new \Monolog\Handler\SlackHandler( 51 | config('epilog.slack.token'), 52 | config('epilog.slack.channel'), 53 | config('epilog.slack.username'), 54 | true, 55 | ':skull:', 56 | \Monolog\Logger::ERROR, 57 | true, 58 | true, 59 | true 60 | ); 61 | $logger->pushHandler($slackHandler); 62 | } 63 | 64 | } 65 | 66 | /** 67 | * Register the application services. 68 | * 69 | * @return void 70 | */ 71 | public function register() 72 | { 73 | // 74 | } 75 | } 76 | --------------------------------------------------------------------------------