123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- declare (strict_types = 1);
- namespace app\middleware;
- use think\facade\Log;
- class HttpLog
- {
- /**
- * 处理请求
- *
- * @param \think\Request $request
- * @param \Closure $next
- * @return Response
- */
- public function handle($request, \Closure $next)
- {
- if ($request->isOptions()) {
- error('OPTIONS请求');
- }
- $data=[
- 'url'=>array_values(array_filter(explode('/',$request->url()))),
- 'method'=>$request->method(),
- 'ip'=>$request->ip(),
- 'param'=>$request->param(),
- 'addtime'=>date('Y-m-d H:i:s')
- ];
- Log::info(json_encode($data,JSON_UNESCAPED_UNICODE));
- return $next($request);
- }
- public function end(\think\Response $response)
- {
- Log::info('响应结束:'.json_encode($response->getData(),JSON_UNESCAPED_UNICODE));
- }
- }
|