1.配置日志文件路径
config/logging.php
追加配置:
'exception' => [
'driver' => 'daily',
'level' => 'debug',
'days' => 5,
'path' => storage_path('logs/exception.log'),
],
2.抛异常文件 所在位置
/bootstrap/app.php
3.修改异常文件
public function render($request, Exception $exception)
{
$code = $exception->getCode();
if ($exception->getCode() != Response::HTTP_OK) {
$logInstance = Log::channel('exception');
$logInstance->info(PHP_EOL);
$logInstance->info('---------------------------------------- 响应 START ------------------------------');
$logInstance->info('请求唯一标识:' . uuid());
$logInstance->info('请求状态码:' . $code);
$logInstance->info('请求地址:' . $request->getPathInfo());
$logInstance->info('请求头:' . json_encode($request->header()));
$logInstance->info('请求参数:' . json_encode($request->all()));
$logInstance->info('错误提示:' . $exception->getMessage());
$logInstance->info('---------------------------------------- 响应 END ------------------------------');
}
return parent::render($request, $exception);
}
4.赋予 logs 权限 & 重新加载配置
chmod -R 777 storage/logs && php artisan config:cache
5.当抛出 异常 时 如下图