pfrug/clear-logs 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pfrug/clear-logs

最新稳定版本:v1.1.0

Composer 安装命令:

composer require pfrug/clear-logs

包简介

Smart cleanup of Laravel logs by file or content date.

README 文档

README

Artisan command to clean up Laravel log files, with support for both single and daily log channels. It preserves logs from the last N days, configurable by content date or file modification time.

Features

  • Works with single and daily log channels
  • Retains logs by configurable number of days
  • Detects dates from log content, not just filenames
  • Supports --dry-run mode (preview changes)
  • Optional file name or mtime-based cleanup for daily logs
  • Clean truncation of large single log files by full log blocks

Installation

Install the package via Composer:

composer require pfrug/clear-logs

Optional: Publish configuration

php artisan vendor:publish --provider="Pfrug\ClearLogs\ClearLogsServiceProvider" --tag="clear-logs-config"

This will publish config/clearlogs.php.

Configuration file options

return [

    // Number of days to preserve (default: 7)
    'days' => 7,

    // Mode used to determine the file date for daily logs
    // Options: 'name' or 'mtime'
    'evalDateByNameOrMTime' => 'name',
];

Usage

Run the command manually:

php artisan log:clear

Or preview the result without modifying files:

php artisan log:clear --dry-run

Override the number of days on the fly:

php artisan log:clear --days=10

Scheduler Integration

To run daily, register the command in your scheduled tasks (app/Console/Kernel.php):

protected function schedule(Schedule $schedule): void
{
    // Run daily at 2 AM
    $schedule->command('log:clear')->dailyAt('02:00');
}

Supported Channels

  • single: The default laravel.log file is parsed and truncated. Only complete log blocks newer than the cutoff are retained.
  • daily: Individual laravel-YYYY-MM-DD.log files are deleted if older than the configured threshold.

License

MIT © P. Frugone

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-20