1. Go to this page and download the library: Download avto-dev/sentry-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
avto-dev / sentry-laravel example snippets
namespace App\Exceptions;
class Handler extends \Illuminate\Foundation\Exceptions\Handler
{
// ...
/**
* Report or log an exception.
*
* @param \Exception $exception
*
* @return void
*/
public function report(\Exception $exception): void
{
if ($this->container->bound('sentry') && $this->shouldReport($exception)) {
try {
$this->container->make('sentry')->captureException($exception);
} catch (\Exception $e) {
$this->container->make(\Psr\Log\LoggerInterface::class)->error(
'Cannot capture exception with sentry: ' . $e->getMessage(), ['exception' => $e]
);
}
}
parent::report($exception);
}
// ...
}
return [
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'sentry'], // Add the Sentry log channel to the stack
],
// ...
],
];
return [
'channels' => [
// ...
'sentry' => [
'driver' => 'sentry',
'level' => null, // The minimum monolog logging level at which this handler will be triggered
// For example: `\Monolog\Logger::ERROR`
'bubble' => true, // Whether the messages that are handled can bubble up the stack or not
],
],
];