Swoft2的日志没有文件数量限制,会导致服务器的日志越积越多
该项目将Monolog中RotatingFileHandler的实现逻辑搬过来,同时继承Swoft2的FileHandler类。
每次生成日志文件时,都会检查相应的日志文件数量,并删除最老的日志。
composer require anhoder/swoft-log-handler在app/bean.php下使用:
'testHandler' => [
'class' => Anhoder\Swoft\Log\RotatingFileHandler::class,
'logFile' => '@runtime/logs/test/test-%d{Y-m-d}.log',
'levels' => 'notice,info,debug,trace,error,warning',
'formatter' => bean('lineFormatter'),
'maxFiles' => 3,
'checkLogInterval' => RotatingFileHandler::INTERVAL_DAY,
],