辅助laravel调试包,记录请求数据、数据库执行SQL语句、相应相关数据。支持file日志、mongodb、mysql(后续更新)。
不足之处希望感兴趣的您指导加以修正。感谢!!!
PHP: ^7.0
Laravel: ^6.0
###镜像包
composer require itedo/itedo-logger -vvv
--providers-- 新增:
IteLog\Providers\IteLoggerProvider::class,
<?php
return [
//是否开启true false
'logger' => 'true',
//驱动 mongodb | file | mysql(后续完善)
'driver' => 'mongodb',
//driver是mongodb 时 需要填写表名
'mongo_table' => 'ite_logger'
];
$routeMiddleware 新增一行请求相应日志
'req.res.log' => \IteLog\Http\Middleware\ReqResLogger::class,
路由加 req.res.log中间件
Route::group([
'middleware' => ['req.res.log']
]);
需配置php扩展 php_mongodb
添加 MongoDB 的数据库的信息:
'mongodb' => [
'driver' => 'mongodb',
'host' => env('MONGODB_HOST', 'localhost'),
'port' => 27017,
'database' => env('MONGODB_DATABASE', 'itelog'),
'username' => env('MONGODB_USERNAME', 'itelog'),
'password' => env('MONGODB_PASSWORD', '123'),
],
##mongodb
MONGODB_HOST=localhost
MONGODB_DATABASE=itelog
MONGODB_USERNAME=itelog
MONGODB_PASSWORD=123
config/logging.php
channels 新增配置日志驱动
'iteLog' => [
'driver' => 'daily',
'path' => storage_path('logs/iteLog/laravel.log'),
'level' => 'debug',
'days' => 10,
],
config/itelog.php 新增配置
//异常开启true false
'exception' => 'true',
app/Exceptions/Handler.php
render()方法内新增
if (config('itelog.exception')) {
$throw = [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'line' => $exception->getLine(),
'trace' => $exception->getTraceAsString(),
];
IteLogFacades::setExceptions($throw);
return response()->json($throw);
}