使用存储打印日志
xuexi 2025-08-21 10:00:28 发表在:PHP 查看数:50
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;//文件存储
class Quanju
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        $url= $request->getUri();//获取用户访问的URL

        //记录一个info级别的信息,并传递用户名和URL
        Log::info('执行全局中间件',['user_id'=>'全局','url'=>$url]);
       // Log::error('这是一个错误。');
        try{
        //执行业务逻辑代码
        }catch (Exception $e){
        //记录异常信息,并传递异常信息对象
        Log::error('发生一个异常',['exception'=>$e]);
        }
        Storage::put('temp'.'.txt', $url);
        return $next($request);
    }
}
最近访问时间:2025-08-30 14:34:52
知识库:376条鸣谢:TAY  备案号:蜀ICP备2024090044号-1