Laravel7.x接⼊Sentry⽇志监控服务步骤
Sentry 是⼀套错误⽇志收集系统,⽀持许多常⽤语⾔的接⼊,也⽀持多种常见框架的接⼊,包括但是不限于 Laravel, Symfony 等等,下图显⽰了部分⽀持接⼊的程序语⾔或框架:
第⼀步、安装 sentry-laravel 扩展包
composer require sentry/sentry-laravel
第⼆步、在 Laravel 异常处理类⾥增加报告 sentry 代码:
public function report(Throwable $exception)
{
if ($this->shouldReport($exception) && app()->bound('sentry')) {
app('sentry')->captureException($exception);
}
parent::report($exception);
}
第三步、终端运⾏sentry:publish命令
php artisan sentry:publish --dsn=19dd95ffda914562b4b86c9ddab7b5e5@o88936.ingest.sentry.io/193722
执⾏成功后,会⾃动将 sentry_dsn 信息写⼊到环境配置 .env ⽂件⾥。
laravel框架下载
第四步、终端运⾏sentry:test命令
$ php artisan sentry:test
[Sentry] DSN discovered!
[Sentry] Generating test Event
[Sentry] Sending test Event
[Sentry] Event sent with ID: d76caf6903bf4990a8842077b304e54e
再登录 sentry 后台查看 issues 问题列表:
接⼊成功了!