LoggerFactoryUtil.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace App\Http\Utils;
  3. class LoggerFactoryUtil extends BaseUtil
  4. {
  5. /**
  6. * 请求开始时间
  7. * @var string $startTime
  8. */
  9. private static $startTime="";
  10. /**
  11. * 类文件名
  12. * @var string $class
  13. */
  14. protected $class="";
  15. /**
  16. * 自定义日志
  17. * @var array $message
  18. */
  19. private static $message=[];
  20. /**
  21. * 执行的sql语句
  22. * @var array $sqlMessage
  23. */
  24. private static $sqlMessage=[];
  25. /**
  26. * 请求ID
  27. * @var string $requestId
  28. */
  29. private static $requestId;
  30. /**
  31. * 是否推送日志
  32. * @var int
  33. */
  34. private static $isPush=0;
  35. /**
  36. * @return int
  37. */
  38. public static function getIsPush(): int
  39. {
  40. return self::$isPush;
  41. }
  42. /**
  43. * @param int $isPush
  44. */
  45. public static function setIsPush(int $isPush): void
  46. {
  47. self::$isPush = $isPush;
  48. }
  49. /**
  50. * @return string
  51. */
  52. public static function getRequestId()
  53. {
  54. return self::$requestId;
  55. }
  56. /**
  57. * @param string $requestId
  58. */
  59. public static function setRequestId(string $requestId)
  60. {
  61. self::$requestId = $requestId;
  62. }
  63. /**
  64. * LoggerFactoryUtil constructor.
  65. */
  66. public function __construct(string $class)
  67. {
  68. $this->class;
  69. }
  70. /**
  71. * 记录自定义日志信息
  72. * @param string $msg
  73. */
  74. public function info(string $msg)
  75. {
  76. $time = date("Y-m-d H:i:s");
  77. self::$message[] = "[$time]".$this->class.":".$msg;
  78. }
  79. /**
  80. * 记录sql日志
  81. * @param string $sql
  82. */
  83. public static function addSqlMessage(string $sql)
  84. {
  85. self::$sqlMessage[] = $sql;
  86. }
  87. /**
  88. * @return array
  89. */
  90. public static function getMessage(): array
  91. {
  92. return self::$message;
  93. }
  94. /**
  95. * @return array
  96. */
  97. public static function getSqlMessage(): array
  98. {
  99. return self::$sqlMessage;
  100. }
  101. /**
  102. * @return string
  103. */
  104. public static function getStartTime(): string
  105. {
  106. return self::$startTime;
  107. }
  108. /**
  109. * @param string $startTime
  110. */
  111. public static function setStartTime(string $startTime): void
  112. {
  113. self::$startTime = $startTime;
  114. }
  115. }