pyaesone17/lapse

2.0.8 2018-08-17 14:04 UTC

This package is not auto-updated.

Last update: 2024-09-13 07:31:00 UTC


README

Example

介绍

Lapse 提供了一个美丽的仪表板来跟踪生产中的错误,无需查找日志文件。此外,它可以通过 Slack 频道和电子邮件警报通知您。而且,它还可以通过来自http://laravel-notification-channels.com/的所有频道进行通知。

Lapse 的幕后依赖于https://laravel.net.cn/docs/5.6/notifications。这意味着理论上 Lapse 可以通过超过 30 种方式通知您的错误,包括 Slack、电子邮件、Nexmo、Trello、Telegram、Facebook、Discord、Pusher、Twillo、Twitter。但我没有对所有频道进行测试,如果您发现任何错误,请提交问题。如果您想了解更多信息,请查看链接。

有关旧版本,请参阅https://github.com/pyaesone17/lapse/tree/v1的文档。

升级指南

如果您正在从版本 1 升级。

请首先删除 config/lapse.php 文件。

安装

通过 Composer 安装

$ composer require pyaesone17/lapse

发布供应商

$ php artisan vendor:publish

在 config/lapse.php 中添加 slack hook url 并定义频道( https://api.slack.com/incoming-webhooks

    'channels' => [
        'slack' => 'https://hooks.slack.com/services/......',
        'mail' => 'your@mail.com'
    ],
    // Currently two notification channels supported
    // Those are slack and email
    // But you can use all of the notifications from http://laravel-notification-channels.com/
    // See the custom channel of my read me file to explore how to integrate
    'via' => ['slack']
$ php artisan vendor:publish

迁移 lapses 表

php artisan migrate

使用方法

之后,在 App\Exceptions\Handler 的 report 方法中注册如下。

    use Pyaesone17\Lapse\ErrorNotifiable;
    ..
    
    class Handler extends ExceptionHandler
    {
        use ErrorNotifiable;
        ...
    
        public function report(Exception $exception)
        {
            if( app()->environment()!='local' ){ // Remove this line if you want lapse to notify in local environment
                $this->sendNotification($exception);
            }
        }
        ...  
    }

Laravel Lapse 的仪表板灵感来源于 Laravel Horizon。就像 Horizon 一样,您可以在 AppServiceProvider 的 boot 方法中配置 Lapse 仪表板的身份验证。添加以下内容到您的 AppServiceProvider 的 boot 方法中。您也可以在此处检查角色权限并限制仪表板。

    \Pyaesone17\Lapse\Lapse::auth(function($request) {
        // return true / false . For e.g.
        return \Auth::check();
    });

要查看仪表板,请将浏览器指向您的应用的 /lapse。例如 laravel.dev/lapse。但由于应用处于本地环境,lapse 不会进行身份验证验证,它会显示所有内容。

要通过 CLI 删除所有 lapse 消息,请运行

$ php artisan clear:lapse

自定义通知频道

您可以使用来自http://laravel-notification-channels.com/的所有通知与 lapse 集成

例如,Telegram

通过 composer 安装频道

    $ composer require laravel-notification-channels/telegram

首先配置 config/lapse.php

    use NotificationChannels\Telegram\TelegramChannel;
    'channels' => [
        'slack' => 'https://hooks.slack.com/services/......',
        'telegram' => 'tele_gram_user_id', //optional
    ],
    // Currently two notification channels is supported built in
    // Those are slack and email
    'via' => ['slack', TelegramChannel::class]

注册 telegram 提供者

// config/app.php
'providers' => [
    ...
    NotificationChannels\Telegram\TelegramServiceProvider::class,
],

设置凭证

    // config/services.php
    'telegram-bot-api' => [
        'token' => env('TELEGRAM_BOT_TOKEN', 'YOUR BOT TOKEN HERE')
    ],

添加通知的格式化器

    use NotificationChannels\Telegram\TelegramMessage;
    use Pyaesone17\Lapse\ErrorNotifiable;
    ..
    
    class Handler extends ExceptionHandler
    {
        use ErrorNotifiable;
        ...
    
        public function report(Exception $exception)
        {
            if( app()->environment()!='local' ){ // Remove this line if you want lapse to notify in local environment
                $this->sendNotification($exception, $this->getFormatters());
            }
        }

        protected function getFormatters()
        {
            $formatters = array(
                'toTelegram' => function($notifiable) {
                    return TelegramMessage::create()
                    ->content("*HELLO!* \n One of your invoices has been paid!");
                }
            );

            return $formatters;
        }
        ...  
    }

新特性

如果您想添加新功能,请随时以问题形式提交

安全

如果您发现任何安全相关的问题,请通过电子邮件promise@gmail.com联系,而不是使用问题跟踪器。

鸣谢

许可证

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