anhoder / swoft-log-handler
Swoft的日志FileHandler,支持最大日志文件限制
Installs: 148
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/anhoder/swoft-log-handler
Requires
- php: >=7.1
- swoft/log: ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-10-06 16:45:42 UTC
README
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, ],