kiwilan/sentinel-laravel

PHP包,用于Laravel将错误发送到Sentinel。

0.0.33 2023-10-11 15:03 UTC

README

PHP Version Laravel Version

Latest Version on Packagist GitHub Tests Action Status Total Downloads License codecov

PHP包,用于Laravel将错误发送到Sentinel

注意

Sentinel是一个开源的错误跟踪工具。

安装

您可以通过Composer安装此包

composer require kiwilan/sentinel-laravel

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="sentinel-config"

这是发布配置文件的内容

return [
    /**
     * If you want to disable Sentinel, set `SENTINEL_ENABLED` to `false`.
     */
    'enabled' => env('SENTINEL_ENABLED', true),
    /**
     * Sentinel host where your application is registered.
     */
    'host' => env('SENTINEL_HOST', 'http://app.sentinel.test'),
    /**
     * Token is used to authenticate your application with Sentinel.
     */
    'token' => env('SENTINEL_TOKEN'),
    /**
     * If you want to throw Sentinel errors for debug, set `SENTINEL_DEBUG` to `true`.
     * WARNING: do not use it on production.
     */
    'debug' => env('SENTINEL_DEBUG', false),
];

使用方法

自动

只需执行sentinel:install Artisan命令。它将自动安装包并为您配置。

php artisan sentinel:install

手动

app/Exceptions/Handler.php

<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
  /**
   * Register the exception handling callbacks for the application.
   */
  public function register(): void
  {
    $this->reportable(function (Throwable $e) {
      \Kiwilan\Sentinel\Facades\Sentinel::register($e);
    });
  }
}

如果您想调试安装,可以将throwErrors设置为true\Kiwilan\Sentinel\Facades\Sentinel::register($e, throwErrors: true)

警告

在生产环境中不要使用throwErrors,如果Sentinel实例不可用,您的应用程序可能会崩溃。

验证您的安装

使用sentinel:test Artisan命令来验证您的安装。

php artisan sentinel:test

您可以通过从一个路由或控制器抛出异常来验证您的安装。

例如,在routes/web.php

Route::get('/debug-sentinel', function () {
  throw new \Exception('Sentinel error!');
});

测试

cp .env.example .env
composer test

更新日志

有关最近更改的更多信息,请参阅更新日志

贡献

有关详细信息,请参阅贡献指南

鸣谢

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件