<?php

namespace Modules\Common\Support\Trace;

use function config;
use function storage_path;

class CustomizeLogger
{
    /**
     * 获取cp订阅的logger
     * @return mixed
     */
    public static function getSubscribeLogger() {
        return self::getLogger('syncCpSubscribe');
    }

    /**
     * 获取通用的logger <br>
     * 使用方法: <br>
     * $logger = CustomizeLogger::getLogger('test'); <br>
     * $logger->debug('kkk', ['aa' => 1]); <br>
     * $logger->info('kkk', ['aa' => 2]); <br>
     * .... <br>
     * @param string $logFileName 文件名
     * @param string $logLevel 日志级别
     * @param int $day 日志保留天数
     * @see \Illuminate\Log\LogManager
     * @link  modules/Common/config/log.php
     * @return \Psr\Log\LoggerInterface $logger
     */
    public static function getLogger($logFileName, $logLevel='info', $day=7): \Psr\Log\LoggerInterface
    {
        $logChannel = \Log::build([
            'driver' => 'daily',
            'days' => config('common.log.days.'.$logFileName, $day),
            'path' => storage_path('logs/'.$logFileName.'.log'),
            'level' => config('common.log.level.'.$logFileName, $logLevel),
        ]);
        return \Log::stack([$logChannel]);
    }
}
