uwakmfon1 / laravel-logs-cleanup
A Laravel package for cleaning old log files automatically.
Fund package maintenance!
v1.0.0
2026-05-24 03:18 UTC
Requires
- php: ^8.4
- illuminate/contracts: ^11.0||^12.0||^13.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^11.0.0||^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- spatie/laravel-ray: ^1.35
README
A lightweight Laravel package for cleaning old entries from storage/logs/laravel.log based on a specified number of days to preserve.
Ideal for large log files containing thousands of lines.
Features
- Cleans only storage/logs/laravel.log
- Preserves recent logs
- Supports dry-run mode
- Creates backup files
- Memory-efficient stream processing
- Safe for large log files
Installation
You can install the package via composer:
composer require uwakmfon1/laravel-logs-cleanup
Publish Configuration
You can publish the config file with:
php artisan vendor:publish --tag="laravel-logs-cleanup-config"
Configuration
File:
config/logs-cleanup.php
Example:
return [ 'log_file' => storage_path('logs/laravel.log'), 'temp_file' => storage_path('logs/laravel-temp.log'), 'create_backup' => true, ];
Usage
Clear Old Logs
Keep logs from the last 3 days:
php artisan logs:clear --except=3
Dry Run
Preview cleanup without deleting logs:
php artisan logs:clear --except=3 --dry-run
How it Works
The package:
- Reads laravel.log line-by-line
- Detects log timestamps
- Removes entries older than the cutoff date
- Writes valid logs into a temporary file
- Replaces the original log safely
This prevents memory exhaustion on large log files.
Supported Log Format
[2026-05-23 10:30:22] local.ERROR: Something happened
Example Output
Cleaning logs older than 3 days...
Backup created successfully.
Removed: 85,421 lines
Kept: 14,579 lines
Log cleanup completed successfully.
Local Package Development
Inside another Laravel app:
composer config repositories.logs-cleaner path ../laravel-logs-cleanup
Install Locally:
composer require uwakmfon1/laravel-logs-cleanup:dev-main
Credits
License
The MIT License (MIT). Please see License File for more information.