From 37f085612e63b0cffbca658d518c2787237d55fc Mon Sep 17 00:00:00 2001 From: Syed Faisal Kazmi Date: Sat, 11 Jul 2020 19:32:13 +0500 Subject: [PATCH 1/3] Issue with publishing config fixed --- config/larvabug.php | 2 +- src/Client/HttpClient.php | 4 ---- src/Handler/LarvaBugExceptionHandler.php | 5 +++++ src/Provider/BootServices.php | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config/larvabug.php b/config/larvabug.php index 3c9baf0..d6f044f 100644 --- a/config/larvabug.php +++ b/config/larvabug.php @@ -28,7 +28,7 @@ * */ 'skip_errors' => [ - '\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class' + 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException', ], /* diff --git a/src/Client/HttpClient.php b/src/Client/HttpClient.php index 181dbaa..da8480c 100644 --- a/src/Client/HttpClient.php +++ b/src/Client/HttpClient.php @@ -18,10 +18,6 @@ class HttpClient */ private $projectSecret; - //Local -// private const POST_EXCEPTION = 'http://larvabug.local/api/v1/exception'; -// private const VALIDATE_CREDENTIALS = 'http://larvabug.local/api/v1/validate/credentials'; -// private const POST_FEEDBACK = 'http://larvabug.local/api/v1/feedback/submit'; //Development private const POST_EXCEPTION = 'http://dev.larvabug.com/api/v1/exception'; diff --git a/src/Handler/LarvaBugExceptionHandler.php b/src/Handler/LarvaBugExceptionHandler.php index cf6a418..ab35bbf 100644 --- a/src/Handler/LarvaBugExceptionHandler.php +++ b/src/Handler/LarvaBugExceptionHandler.php @@ -127,6 +127,11 @@ private function skipError($class) return false; } + public function shouldCollectFeedback(\Exception $exception) + { + return !$this->skipError(get_class($exception)); + } + /** * Validate env credentials from larvabug * diff --git a/src/Provider/BootServices.php b/src/Provider/BootServices.php index 381356e..611e97b 100644 --- a/src/Provider/BootServices.php +++ b/src/Provider/BootServices.php @@ -54,7 +54,7 @@ private function publishConfig() { if (function_exists('config_path')) { $this->publishes([ - __DIR__ . '../../config/larvabug.php' => config_path('larvabug.php'), + __DIR__ . '/../../config/larvabug.php' => config_path('larvabug.php'), ]); } } From 39056fdc20aa37670579cdf91101a975964ad08c Mon Sep 17 00:00:00 2001 From: Syed Faisal Kazmi Date: Sat, 11 Jul 2020 20:59:59 +0500 Subject: [PATCH 2/3] readme added --- readme.md | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 readme.md diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..317f488 --- /dev/null +++ b/readme.md @@ -0,0 +1,98 @@ +

+ +

+ +# LarvaBug +Laravel 5.2+ package for logging errors to [larvabug.com](https://www.larvabug.com) + +[![Software License](https://poser.pugx.org/larvabug/larvabug-laravel/license.svg)](LICENSE.md) +[![Latest Version on Packagist](https://poser.pugx.org/larvabug/larvabug-laravel/v/stable.svg)](https://packagist.org/packages/larvabug/larvabug-laravel) +[![Total Downloads](https://poser.pugx.org/larvabug/larvabug-laravel/d/total.svg)](https://packagist.org/packages/larvabug/larvabug-laravel) + + +## Installation +You can install the package through Composer. +```bash +composer require larvabug/larvabug-laravel +``` + +Add the LarvaBug service provider and facade in config/app.php: +```php + +'providers' => [ + LarvaBug\Provider\ServiceProvider::class, +], + +'aliases' => [ + 'LarvaBug' => \LarvaBug\Facade\LarvaBug::class +], + +``` +Then publish the config file of the larvabug using artisan command. +```bash +php artisan vendor:publish --provider="LarvaBug\Provider\ServiceProvider" +``` +File (`config/larvabug.php`) contains all the configuration related to bug reporting. + +Note: by default production and local environments will report errors. To modify this edit your larvabug configuration environment array. + +## Environment variables + Need to define two environment variable and their values. + + ``` + LB_PROJECT_ID= + LB_SECRET= + ``` +Get these variable values under setting page of the project at [larvabug.com](https://www.larvabug.com) + +# Reporting unhandled exceptions + +Add larvabug reporting to `app/Exceptions/Handler.php` file of laravel. + +```php +public function report(Exception $exception) +{ + LarvaBug::report($exception); + parent::report($exception); +} +``` + +# Reporting handled exceptions + +In case of handled exceptions, exceptions can be reported to larvabug by using `LarvaBug` facade: + +```php +try { + //Code here + }catch (\Exception $exception){ + LarvaBug::report($exception); +} +``` + +#Logging specific data + +To log specific data to LarvaBug use `log()` method of LarvaBug facade: + +```php +$metaData = ['custom_data' => ['x','y','z']]; //Array +LarvaBug::log('Log message here',$metaData); +``` + +# User feedback + +LarvaBug provides the ability to collect feedback from user when an error occurs, +LarvaBug shows feedback collection page and then feedback is added with the exception report, +to enable this functionality simply need to add `collectFeedback()` method in `render()` method of `app/Exceptions/Handler.php` + +```php +public function render($request, Exception $exception) +{ + if (LarvaBug::shouldCollectFeedback($exception) && !$request->wantsJson()) { + return LarvaBug::collectFeedback(); + } + return parent::render($request, $exception); +} +``` + +## License +The larvabug package is open source software licensed under the [license MIT](http://opensource.org/licenses/MIT) From f722d299e489a2f4cbc1019b68e35e78ded43ce3 Mon Sep 17 00:00:00 2001 From: Syed Faisal Kazmi Date: Sat, 11 Jul 2020 21:10:13 +0500 Subject: [PATCH 3/3] readme image url fixed --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 317f488..8f8d8f1 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,5 @@

- +

# LarvaBug