<?php
namespace App\Libs\Classes;

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Illuminate\Log\Writer;

class BLogger
{
    // 所有的LOG都要求在这里注册
    const LOG_ERROR = 'error';
    const LOG_MSG = 'msg';
    const LOG_WARN = 'warn';
    const LOG_MSG_QUEUE = 'msg_queue';// 消息队列的日志单独放文件

    private static $loggers = array();

    // 获取一个实例
    public static function getLogger($type = self::LOG_MSG, $day = 3)
    {
        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;
    }
}

?>
