escode/larax

此包的最新版本(v1.0)没有可用的许可证信息。

laravel 异常日志包

v1.0 2021-01-04 21:49 UTC

This package is auto-updated.

Last update: 2024-09-07 02:06:28 UTC


README

Larax 是一个 Laravel 包,帮助我们记录 Laravel 应用中发生的异常,并在异常发生时通过所需的所有数据(如用户发送到正文中的数据、头信息、用户 IP、用户 ID 及其 guard)通知我们找出问题的原因。

Latest Version on Packagist Total Downloads

安装

在 composer.json 中添加此包。

    {
        "require": {
            "escode/larax": "1.*"
        }
    }

或在终端运行: composer require escode/larax

添加 Larax 服务提供者

打开 "/config/app.php",并将 Escode\Larax\LaraxServiceProvider::class 添加到 providers 数组中

示例

 'providers' => [
    Escode\Larax\LaraxServiceProvider::class,

发布配置文件

php artisan vendor:publish --tag=larax-config

迁移数据库表

php artisan migrate

使 Larax 处理异常

进入 "/app/Exceptions/Handler.php",使其扩展 Escode\Larax\ExceptionHandler

示例

use Escode\Larax\ExceptionHandler;
class Handler extends ExceptionHandler
{

配置

打开 "/config/larax.php",此文件可以帮助您轻松配置和控制 Larax。

您可以设置允许访问网站异常页面的中间件。

您可以设置允许通过 API 访问异常页面的中间件。

您可以在异常发生时控制要保存的数据。

您可以告诉 Larax 检测用户并保存其 ID 及其 guard 与异常数据。

您可以忽略一些键“从头信息数据中删除”例如“Authorization”。

您可以忽略一些字段“从请求数据中删除”例如“password, image, token”。

您可以告诉 larax 在异常发生时通过发送电子邮件通知您。

return [
     //set your middleware that's allow to access exceptions pages on website
    'middleware'=>'auth',
    
    //api middleware
    'ApiMiddleware'=>'AuthLaraxApi',
    
    //exceptions data you want to store it
    'exception_data'=>[
        'ip'=>true,
        'url'=>true,
        'headers'=>true,
        'body'=>true,
    ],
    
    // Note: if you enable detect user in exception larax will push StartSession::class and EncryptCookies::class in $middleware Kernel.php
    // and you should be comment StartSession::class  from $middlewareGroups => web
   
    'detect_user'=>false,
    //array of guards names will use it for detect user id
    'guards'=>['auth'],
    
    //ignore fields in request headers (this fields not saved in db)
    'ignore_headers'=>[
        'Authorization','cookie'
    ],
    
    //ignore fields in request (this fields not saved in db)
    'ignore_inputs'=>[
        'image','password','password_confirmation'
    ],
    
    //send email when exception happened
    //enable send emails
    'enable_email'=>true,

    //email list you want send notify them with exception data
    'emails'=>[
       //example
        //'es.code@yahoo.com',
    ],

]

如何使用

打开 "https://:8000/larax/exceptions" 查看您的应用程序中发生的异常。

Larax

Larax exception info

用户

larax 中的用户用于允许用户使用 Larax API 读取异常。

API

您可以通过对 "https://:8000/api/larax/exceptions" 进行 "GET" 请求来通过 API 读取您应用程序的异常数据,使用用户密钥作为 bearer token