Laravel 5.2+ package for logging errors to larvabug.com
You can install the package through Composer.
composer require larvabug/larvabug-laravel
Add the LarvaBug service provider and facade in config/app.php:
'providers' => [
LarvaBug\Provider\ServiceProvider::class,
],
'aliases' => [
'LarvaBug' => \LarvaBug\Facade\LarvaBug::class
],
Then publish the config file of the larvabug using artisan command.
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.
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
Add larvabug reporting to app/Exceptions/Handler.php
file of laravel.
public function report(Exception $exception)
{
LarvaBug::report($exception);
parent::report($exception);
}
In case of handled exceptions, exceptions can be reported to larvabug by using LarvaBug
facade:
try {
//Code here
}catch (\Exception $exception){
LarvaBug::report($exception);
}
#Logging specific data
To log specific data to LarvaBug use log()
method of LarvaBug facade:
$metaData = ['custom_data' => ['x','y','z']]; //Array
LarvaBug::log('Log message here',$metaData);
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
public function render($request, Exception $exception)
{
if (LarvaBug::shouldCollectFeedback($exception) && !$request->wantsJson()) {
return LarvaBug::collectFeedback();
}
return parent::render($request, $exception);
}
The larvabug package is open source software licensed under the license MIT