Logger.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace UCore\Helper;
  3. use Illuminate\Support\Facades\Log;
  4. /**
  5. * 日志助手类
  6. */
  7. class Logger
  8. {
  9. /**
  10. * 记录调试日志
  11. *
  12. * @param string $msg 日志消息
  13. * @param array $data 日志数据
  14. * @return void
  15. */
  16. static public function debug($msg, $data = [])
  17. {
  18. Log::debug($msg.' '.json_encode($data));
  19. }
  20. /**
  21. * 错误日志
  22. * @param $msg
  23. * @param $data
  24. * @return void
  25. */
  26. static public function error($msg, $data = [])
  27. {
  28. Log::error($msg . ' ' . json_encode($data));
  29. }
  30. /**
  31. * 错误记录
  32. * @param $msg
  33. * @param \Exception $exception
  34. * @return void
  35. */
  36. static public function exception($msg, \Throwable $exception)
  37. {
  38. $data = [
  39. 'msg' => $exception->getMessage(),
  40. 'trace_string' => $exception->getTraceAsString(),
  41. ];
  42. Log::error($msg . ' ' . json_encode($data));
  43. }
  44. static public function info($msg, $data = [])
  45. {
  46. Log::info($msg . ' ' . json_encode($data));
  47. }
  48. }