SysLog.php 840 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\admin\controller\syslog;
  3. use think\Db;
  4. use think\Request;
  5. use think\Session;
  6. /**
  7. * 系统日志
  8. * @icon fa fa-institution
  9. */
  10. class SysLog
  11. {
  12. /**
  13. * 记录系统日志
  14. * @param $module
  15. * @param $type
  16. * @param $text
  17. * @author matielong
  18. */
  19. public static function recode($module, $type, $text)
  20. {
  21. $ip = Request::instance()->ip();
  22. $admin = Session::get("admin");
  23. $txt = is_array($text) ? json_encode($text) : $text;
  24. $insert = [
  25. 'id' => makeNew16Uid(),
  26. 'uid' => $admin['id'],
  27. 'module' => $module,
  28. 'type' => $type,
  29. 'txt' => $txt,
  30. 'ip' => $ip,
  31. 'cdate' => date('Y-m-d H:i:s'),
  32. ];
  33. Db::table('sys_logs')->insert($insert);
  34. }
  35. }