WriteLog.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\common\middleware;
  4. use app\common\model\AdminLog;
  5. use app\Request;
  6. use Closure;
  7. use think\facade\Log;
  8. /**
  9. * 全局日志记录
  10. * Class WriteLog
  11. * @package app\middleware
  12. */
  13. class WriteLog
  14. {
  15. /**
  16. * @param Request $request
  17. * @param Closure $next
  18. * @return mixed
  19. */
  20. public function handle(Request $request, Closure $next): mixed
  21. {
  22. $response = $next($request);
  23. // 添加中间件执行代码
  24. Log::record("===============" . getNow() . "全局日志记录===============", "debug");
  25. Log::record("request:" . $request->url(true), "debug");
  26. Log::record('REFERER ' . (array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : ""));
  27. Log::record('GET ' . json_encode($_GET, JSON_UNESCAPED_UNICODE));
  28. Log::record('POST ' . json_encode($_POST, JSON_UNESCAPED_UNICODE));
  29. Log::record('cookie ' . json_encode($_COOKIE, JSON_UNESCAPED_UNICODE));
  30. Log::record('param ' . json_encode(input('param.'), JSON_UNESCAPED_UNICODE));
  31. return $response;
  32. }
  33. }