cesargb / laravel-logs-rotate
带压缩的日志文件轮转
2.5.0
2024-03-09 10:17 UTC
Requires
- php: ^8.0
- cesargb/php-log-rotation: ^2.7
- illuminate/config: ^10.0|^11.0
- illuminate/console: ^10.0|^11.0
- illuminate/log: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- monolog/monolog: ^2.0|^3.0|^11.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- larastan/larastan: ^2.0
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.5
README
此包允许您使用压缩轮转Laravel记录文件。如果使用记录通道 single
(StreamHandler),此方法很有用。
安装
此包可用于Laravel 5.5或更高版本。
您可以通过Composer安装此包
composer require cesargb/laravel-logs-rotate
用法
目前,每天00:00应用程序执行一个计划以轮转Laravel记录文件。
配置
如果您需要更改频率或其他功能,您可以修改配置文件。
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Cesargb\LaravelLog\RotateServiceProvider" --tag=config
这是已发布的config/rotate.php配置文件的内容
<?php return [ /* |-------------------------------------------------------------------------- | Compression Enable |-------------------------------------------------------------------------- | | This option defines if the file rotated must be compressed. | If you prefer not compress file, set this value at false. */ 'log_compress_files' => true, /* |-------------------------------------------------------------------------- | Schedule Rotate |-------------------------------------------------------------------------- | | Determine when must be run the cron. | You can disable the schedule change the option enable at false. | You can change the frequency with option cron. | */ 'schedule' => [ 'enable' => true, 'cron' => '0 0 * * *', ], /* |-------------------------------------------------------------------------- | Max Files Rotated |-------------------------------------------------------------------------- | | This value determine the max number of files rotated in the archive folder. | */ 'log_max_files' => env('LOG_MAX_FILES', 5), /* |-------------------------------------------------------------------------- | Other files to rotated |-------------------------------------------------------------------------- | | Array the other foreing files | | Example: | 'foreign_files' => [ storage_path('/logs/worker.log') | ] | */ 'foreign_files' => [] ];
命令
您有一个命令可以轮转其他文件,rotate:files
php artisan rotate:files --help Description: Rotate files Usage: rotate:files [options] Options: -f, --file[=FILE] Files to rotate (multiple values allowed) -c, --compress[=COMPRESS] Compress the file rotated [default: "true"] -m, --max-files[=MAX-FILES] Max files rotated [default: "5"] -d, --dir[=DIR] Dir where archive the file rotated
事件
每次轮转文件时,都会发生以下事件之一
RotateWasSuccessful
Cesargb\LaravelLog\Events\RotateWasSuccessful
当轮转成功时将触发此事件。
它有两个公开属性
- filename: 要轮转的文件的完整路径
- filenameTarget: 轮转的文件的完整路径
RotateHasFailed
Cesargb\LaravelLog\Events\RotativeHandler
在轮转过程中发生错误时将触发此事件。
它有两个公开属性
- filename: 要轮转的文件的完整路径
- exception: 继承PHP异常类的对象。
关于
您只能轮转使用记录通道StreamHandler生成的日志文件。
测试
使用以下命令运行测试
composer test
升级
有关详细信息,请参阅 UPGRADING
贡献
欢迎任何贡献。
许可证
MIT许可证(MIT)。有关更多信息,请参阅 许可证文件