niveshsaharan / laravel-logcleaner
保持Laravel日志小而整洁。
1.2.0
2023-04-26 07:45 UTC
Requires
- php: ^7.3|^8.0
- illuminate/console: ^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/filesystem: ^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: 4.*|5.*|6.*|^7.0|^8.0
- phpunit/phpunit: ^8.4|^9.0
This package is auto-updated.
Last update: 2024-09-26 11:19:42 UTC
README
日志可能会变得非常庞大。此包可以帮助节省服务器空间并保持Laravel日志文件小。
- 将每日日志修剪到指定的行数,以防止其变得过大。
- 删除旧日志,只保留指定数量的最新日志文件。
安装
您可以通过composer安装此包
composer require accentinteractive/laravel-logcleaner
可选地,您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Accentinteractive\LaravelLogcleaner\LaravelLogcleanerServiceProvider" --tag="config"
使用方法
您可以从命令行使用logcleaner:run
或将其设置为cron作业。
命令行使用;
// Get info about the command and options php artisan logcleaner:run --help // Trim big log files and delete old log files php artisan logcleaner:run // Pass the number of lines to keep when trimming log files. Overrides the config setting. // This overrides the default set in config php artisan logcleaner:run --keeplines=10000 // Pass the number of files to keep when deleting old log files. Overrides the config setting. // This overrides the default set in config php artisan logcleaner:run --keepfiles=7 // Run without actually cleaning any logs php artisan logcleaner:run --dry-run
cron作业使用,添加到App\Console\Kernel
protected function schedule(Schedule $schedule) { $schedule->command('logcleaner:run')->daily()->at('01:00'); }
当然,您也可以在定义cron作业时传递选项。
protected function schedule(Schedule $schedule) { $schedule->command('logcleaner:run', ['--keeplines' => 5000, '--keepfiles' => 14])->daily()->at('01:00'); }
配置设置
您可以将配置设置传递给修改行为。
log_files_to_keep
: 删除旧日志文件时保留的日志文件数量。此配置设置会被--keepfiles
选项覆盖。log_lines_to_keep
: 修剪日志文件时保留的行数。此配置设置会被--keeplines
选项覆盖。exclude
: 要排除处理的文件名数组,使用通配符。trimming_enabled
: 启用日志文件修剪。默认值为true
。deleting_enabled
: 启用旧日志文件删除。默认值为true
。
您还可以直接传递选项。
--keeplines=2000
--keepfiles=7
--dry-run
测试
composer test
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
贡献
有关详细信息,请参阅CONTRIBUTING。
安全性
如果您发现任何安全问题,请通过电子邮件joost@accentinteractive.nl联系,而不是使用问题跟踪器。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。