# Laravel接口调用监控插件 **Repository Path**: max-l/laravel_log ## Basic Information - **Project Name**: Laravel接口调用监控插件 - **Description**: 通过中间件记录每次api调用,并记录到数据库。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2024-10-23 - **Last Updated**: 2024-10-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Laravel Log 使用教程 开发目的:监控Laravel系统中的请求信息,报错、超时等情况。 ## 1. 使用说明 ### 1.1 下载依赖 ```shell composer require hzanchu/laravel_log ``` ### 1.2 注册中间件 `app/Http/Kernel.php`: ```php protected $middlewareGroups = [ 'api' => [ Anchu\LaravelLog\Middlewares\LogRequest::class, ], ]; ``` ### 1.3 注入代码 捕获错误信息:`app/Exceptions/Handler.php` ```php public function register() { $this->reportable(function (Throwable $e) { // 捕获异常到临时变量 $_COOKIE['exception'] = json_encode([ 'code' => $exception->getCode(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'message' => $exception->getMessage() ]); }); } ``` ### 1.4 配置参数 在多个数据库的情况下,需要如下参数指定链接: `.env`: ```shell MONITOR_DB_CONNECTION=mysql LOG_TOKEN=xxxx ```