如何将 PSR 日志文件更改为每天一个

How to change PSR log files as only one per day

我使用 PSR 记录器来获取日志。但它只会为所有日期创建一个文件。我需要为每个日期获取单独的日志文件。怎么做?

    require_once '../../logger/vendor/autoload.php';
    require_once '../../logger/Psr/Log/Logger.php';
    use Katzgrau\KLogger\Logger;
    use Psr\Log\LogLevel;


    $logPath = '/var/www/html/logs';
    $logger = new Logger($logPath, LogLevel::DEBUG, array ( 'filename' => 'driver_api' , 'extension' => 'log' ));
    $logger->log( $level,  $message , $context);

`

使用日志旋转器

protected function log_rotate($logpath, $filename, $extention){
    $logfilename = $logpath.'/'.$filename.'.'.$extention; //not needed when included
    $logfilestokeep = 15;
    $fileDate = '';



    if (file_exists($logfilename)) {
        if (date("Y-m-d", filemtime($logfilename)) !== date('Y-m-d')) {
            $fileDate = date("Y-m-d", filemtime($logfilename));
            $newName = $logpath .'/'.$filename. "_" . $fileDate.'.'.$extention;

            if (file_exists($logfilename)) {
                rename($logfilename, $newName);
            }

        }
    }
}