Log.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Log.php UTF-8
  4. * 火树错误Log处理
  5. *
  6. * @date : 2020/1/11 15:08
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOUNION 8.5
  11. */
  12. namespace huolib\tool;
  13. class Log {
  14. /**
  15. * 生成调用栈
  16. *
  17. * @return false|string
  18. */
  19. public static function getBacktrace() {
  20. ob_start();
  21. debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
  22. return ob_get_clean();
  23. }
  24. /**
  25. * 输出错误日志
  26. *
  27. * @param array $debug_param
  28. * @param array $result
  29. * @param int $step
  30. * @param array $other
  31. * @param string $type
  32. *
  33. * @return bool
  34. */
  35. public static function outErrorLog($debug_param, $result = [], $step = 0, $other = [], $type = \think\Log::ERROR) {
  36. $_request_param = request()->param();
  37. if (!empty($_request_param)) {
  38. \think\Log::record('[ REQUEST ] '.var_export(request()->param(), true), $type);
  39. }
  40. $_args = get_val($debug_param, 'args', []);
  41. if (!empty($_args)) {
  42. \think\Log::record('[ ARGS ] '.var_export($_args, true), $type);
  43. }
  44. if (!empty($result)) {
  45. \think\Log::record('[ RESULT ] '.var_export($result, true), $type);
  46. }
  47. \think\Log::record('[ TRACE ] '.var_export(self::getBacktrace(), true), $type);
  48. if (!empty($step)) {
  49. \think\Log::record('[ STEP ] '.var_export($step, true), $type);
  50. }
  51. if (!empty($other)) {
  52. \think\Log::record('[ OTHER ] '.var_export($other, true), $type);
  53. }
  54. return \think\Log::save();
  55. }
  56. }