| 12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace App\Library;
- use Illuminate\Log\Writer;
- use Illuminate\Support\Facades\Log;
- use Monolog\Handler\RotatingFileHandler;
- use Monolog\Logger;
- /**
- * 自定义日志类实现
- * Class BLogger
- * @package App\Library
- */
- class BLogger
- {
- // 所有的LOG都要求在这里注册
- const LOG_ERROR = 'error';
- const LOG_DEBUG = 'debug';
- const LOG_INFO = 'info';
- private static $loggers = [];
- // 获取一个实例
- public static function getLogger($type = self::LOG_ERROR, $day = 30)
- {
- return ;
- if (empty(self::$loggers[$type])) {
- self::$loggers[$type] = new Writer(new Logger($type));
- self::$loggers[$type]->useDailyFiles(storage_path() . '/logs/' . $type . '.log', $day);
- }
- $log = self::$loggers[$type];
- return $log;
- }
- }
|