$request->url(), 'request_body' => json_encode(request()->post(), JSON_UNESCAPED_UNICODE), 'request_header' => json_encode(request()->header(), JSON_UNESCAPED_UNICODE), 'ip' => $request->ip(), 'status_code' => 500, 'response_body' => json_encode($this->convertExceptionToArray($exception), JSON_UNESCAPED_UNICODE), 'create_time' => date('Y-m-d H:i:s'), ]); }catch (\Exception $e){ } } // 使用内置的方式记录异常日志 parent::report($exception); } /** * 收集异常数据 * 重写父类此方法,将Server/Request Data进行转码,解决windows环境下,出现异常时,页面输出空白的问题 * @param Throwable $exception * @return array */ protected function convertExceptionToArray(Throwable $exception): array { $data = parent::convertExceptionToArray($exception); $data['tables']['Server/Request Data'] = $this->changeToUtf8($this->app->request->server()); return $data; } /** * 将获取的服务器信息中的中文编码转为utf-8 * 修复在开启debug模式时出现的Malformed UTF-8 characters 错误 * @access protected * @param $data array * @return array 转化后的数组 */ protected function changeToUtf8(array $data): array { foreach ($data as $key => $value) { $data[$key] = mb_convert_encoding($value, "UTF-8", "GBK, GBK2312"); } return $data; } }