BLogger.php 828 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Library;
  3. use Illuminate\Log\Writer;
  4. use Illuminate\Support\Facades\Log;
  5. use Monolog\Handler\RotatingFileHandler;
  6. use Monolog\Logger;
  7. /**
  8. * 自定义日志类实现
  9. * Class BLogger
  10. * @package App\Library
  11. */
  12. class BLogger
  13. {
  14. // 所有的LOG都要求在这里注册
  15. const LOG_ERROR = 'error';
  16. const LOG_DEBUG = 'debug';
  17. const LOG_INFO = 'info';
  18. private static $loggers = [];
  19. // 获取一个实例
  20. public static function getLogger($type = self::LOG_ERROR, $day = 30)
  21. {
  22. return ;
  23. if (empty(self::$loggers[$type])) {
  24. self::$loggers[$type] = new Writer(new Logger($type));
  25. self::$loggers[$type]->useDailyFiles(storage_path() . '/logs/' . $type . '.log', $day);
  26. }
  27. $log = self::$loggers[$type];
  28. return $log;
  29. }
  30. }