## 中间件日志
~~~
<?php
declare (strict_types=1);
namespace app\middleware;
use app\BaseController;
use app\Request;
use think\facade\Log as Logger;
class Log
{
// 日志中间件
public function handle($request, \Closure $next)
{
/**
* 记录访问信息
* -IP 请求方式 请求url
* -头部参数
* -请求参数
*/
$host = $request->ip().' '.$request->method().' '.$request->url(true);
$response = $next($request);
//$return = json_encode(json_decode($response->getContent(), 1), JSON_UNESCAPED_UNICODE).chr(10);
Logger::write($host, 'HOST');
Logger::write($request->header(), 'HEADER');
Logger::write($request->param(), 'PARAM');
Logger::write($response->getContent(), 'Response');
return $response;
}
}
~~~