yocmen/sneaker

一种简单的方法,用于在服务器上发生异常时,向Laravel应用程序发送带有堆栈跟踪的电子邮件。

v1.2 2018-03-07 16:15 UTC

This package is not auto-updated.

Last update: 2024-09-18 20:29:58 UTC


README

一种简单的方法,用于在服务器上发生异常时,向Laravel应用程序发送带有堆栈跟踪的电子邮件。

sneaker example image

安装

通过composer安装

$ composer require yocmen/sneaker ^1.0

配置Laravel

安装操作完成后,只需将服务提供者添加到项目的config/app.php文件中

服务提供者

Yocmen\Sneaker\SneakerServiceProvider::class,

添加Sneaker异常捕获

将异常捕获添加到app/Exceptions/Handler.php

public function report(Exception $exception)
{
    app('sneaker')->captureException($exception);

    parent::report($exception);
}

配置文件

使用以下命令创建Sneaker配置文件

$ php artisan vendor:publish --provider="Yocmen\Sneaker\SneakerServiceProvider"

配置文件将被发布到config/sneaker.php

以下是Sneaker使用的配置属性。

silent

该包默认包含'silent' => true,配置,因为你可能不希望在开发环境中启用错误电子邮件。特别是如果你已经设置了'debug' => true,

'silent' => env('SNEAKER_SILENT', true),

当发生异常时发送电子邮件,请在.env文件中设置SNEAKER_SILENT=false

capture

它包含应捕获的异常类型列表。您可以在此处添加您希望发送错误电子邮件的异常。

默认情况下,该包已包含Symfony\Component\Debug\Exception\FatalErrorException::class

'capture' => [
    Symfony\Component\Debug\Exception\FatalErrorException::class,
],

您也可以在$capture数组中使用'*',这将捕获每个异常。

'capture' => [
    '*'
],

要使用此功能,您应该在app/Exceptions/Handler.php中添加以下代码

public function report(Exception $exception)
{
    if ($this->shouldReport($exception)) {
        app('sneaker')->captureException($exception);
    }

    parent::report($exception);
}

这是错误电子邮件的收件人列表。

'to' => [
        // 'hello@example.com',
    ],

ignored_bots

这是不应发送错误电子邮件的机器人列表。

'ignored_bots' => [
    'googlebot',        // Googlebot
    'bingbot',          // Microsoft Bingbot
    'slurp',            // Yahoo! Slurp
    'ia_archiver',      // Alexa
],

自定义

如果您需要自定义电子邮件的主题和正文,请运行以下命令

$ php artisan vendor:publish --provider="Yocmen\Sneaker\SneakerServiceProvider"

注意 - 如果您已经运行过此命令,则不要再次运行。

现在,电子邮件的主题和正文视图位于resources/views/vendor/sneaker目录中。

我们已经传递了抛出的异常对象$exception到视图中,您可以使用它来自定义视图以符合您的需求。

安全

如果您发现任何与安全相关的问题,请通过电子邮件发送到amit.gupta@squareboat.com,而不是使用问题跟踪器。

致谢

关于Squareboat

Squareboat是一家位于印度古尔冈的专注于创业公司和产品开发的初创公司。您可以在GitHub上找到我们所有开源项目的概述在此

许可证

MIT许可证。有关更多信息,请参阅许可证文件。版权所有© 2016 SquareBoat