laravel-logs-cleanup maintained by uwakmfon1
Laravel Logs Cleanup
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 entire log file
php artisan logs:clear
Clear old logs, keep recent days
Keep logs from the last 3 days:
php artisan logs:clear --except=3
Dry Run
Preview cleanup without deleting logs:
php artisan logs:clear --dry-run
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.