Log.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace Yansongda\Supports;
  3. /**
  4. * @method static void emergency($message, array $context = array())
  5. * @method static void alert($message, array $context = array())
  6. * @method static void critical($message, array $context = array())
  7. * @method static void error($message, array $context = array())
  8. * @method static void warning($message, array $context = array())
  9. * @method static void notice($message, array $context = array())
  10. * @method static void info($message, array $context = array())
  11. * @method static void debug($message, array $context = array())
  12. * @method static void log($message, array $context = array())
  13. */
  14. class Log extends Logger
  15. {
  16. /**
  17. * instance.
  18. *
  19. * @var \Psr\Log\LoggerInterface
  20. */
  21. private static $instance;
  22. /**
  23. * Bootstrap.
  24. */
  25. private function __construct()
  26. {
  27. }
  28. /**
  29. * __call.
  30. *
  31. * @author yansongda <me@yansongda.cn>
  32. *
  33. * @param string $method
  34. * @param array $args
  35. *
  36. * @throws \Exception
  37. */
  38. public function __call($method, $args): void
  39. {
  40. call_user_func_array([self::getInstance(), $method], $args);
  41. }
  42. /**
  43. * __callStatic.
  44. *
  45. * @author yansongda <me@yansongda.cn>
  46. *
  47. * @param string $method
  48. * @param array $args
  49. *
  50. * @throws \Exception
  51. */
  52. public static function __callStatic($method, $args): void
  53. {
  54. forward_static_call_array([self::getInstance(), $method], $args);
  55. }
  56. /**
  57. * getInstance.
  58. *
  59. * @author yansongda <me@yansongda.cn>
  60. *
  61. * @return \Yansongda\Supports\Logger
  62. */
  63. public static function getInstance(): Logger
  64. {
  65. if (is_null(self::$instance)) {
  66. self::$instance = new Logger();
  67. }
  68. return self::$instance;
  69. }
  70. /**
  71. * setInstance.
  72. *
  73. * @author yansongda <me@yansongda.cn>
  74. *
  75. * @param \Yansongda\Supports\Logger $logger
  76. *
  77. * @throws \Exception
  78. */
  79. public static function setInstance(Logger $logger): void
  80. {
  81. self::$instance = $logger;
  82. }
  83. }