cesargb / php-log-rotation
PHP 日志文件轮转类
2.7.1
2023-01-15 14:07 UTC
Requires
- php: ^8.0
Requires (Dev)
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-18 07:45:31 UTC
README
此 PHP 包允许您轮转并压缩日志文件。
注意:如果您已安装版本 1,请阅读此内容。
安装
您可以通过 composer 安装此包:
composer require cesargb/php-log-rotation
使用方法
use Cesargb\Log\Rotation; use Cesargb\Log\Exceptions\RotationFailed; $rotation = new Rotation(); $rotation ->compress() // Optional, compress the file after rotated. Accept level compression argument. ->files(30) // Optional, files are rotated 30 times before being removed. Default 366 ->minSize(1024) // Optional, are rotated when they grow bigger than 1024 bytes. Default 0 ->truncate() // Optional, truncate the original log file in place after creating a copy, instead of moving the old log file. ->then(function ($filenameTarget, $filenameRotated) {}) // Optional, to get filename target and original filename ->catch(function (RotationFailed $exception) {}) // Optional, to catch a exception in rotating ->finally(function ($message, $filenameTarget) {}) // Optional, this method will be called when the process has finished ->rotate('file.log');
或者您可以在构造函数中定义选项
use Cesargb\Log\Rotation; use Cesargb\Log\Exceptions\RotationFailed; $rotation = new Rotation([ 'files' => 1, 'compress' => true, // Set level compression or true to default level. Default false 'min-size' => 10, 'truncate' => false, 'then' => function ($filename) {}, 'catch' => function (RotationFailed $exception) {}, 'finally' => function ($message, $filename) {}, ]); $rotation->rotate('file.log');
测试
使用以下命令运行测试:
composer test
贡献
欢迎任何形式的贡献。