ExceptionLog.php 773 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. //异常日志写入数据库
  3. namespace listen;
  4. use app\model\Log;
  5. class ExceptionLog
  6. {
  7. public function handle($event){
  8. $content = request()->except(['s', '_pjax']);
  9. if ($content) {
  10. foreach ($content as $k => $v) {
  11. if (is_string($v) && strlen($v) > 200 || stripos($k, 'password') !== false) {
  12. unset($content[$k]);
  13. }
  14. }
  15. }
  16. $data['application_name'] = app('http')->getName();
  17. $data['weid'] = weid();
  18. $data['url'] = request()->url(true);
  19. $data['ip'] = request()->ip();
  20. $data['useragent'] = request()->server('HTTP_USER_AGENT');
  21. $data['content'] = json_encode($content);
  22. $data['errmsg'] = $event;
  23. $data['type'] = 3;
  24. Log::create($data);
  25. }
  26. }