jiordiviera/laravel-log-cleaner
Laravel Log Cleaner helps you purge old Laravel log files automatically. Configure retention rules and schedule cleanup via Artisan/cron to keep storage tidy, prevent large logs, and reduce disk usage with minimal setup.
php artisan vendor:publish --tag="log-cleaner-config")LogCleaning, LogCleaned, LogFileCleanedInvalidDaysExceptionNoLogFilesExceptionInvalidLogLevelExceptionInvalidPatternExceptionPermissionExceptionBackupExceptionDiskSpaceExceptionFileLockExceptionZlibException--no-lock - Disable file locking--no-events - Disable event dispatchingcomposer format, composer lint)CreatesLogFiles trait for testing--file=FILENAME): Clean specific log files instead of all logsLogCleaner::clear() directly in code for custom integrationsClearLogCommand and LogCleaner classLogCleaner logic for consistencyLogCleaner class internally, reducing maintenance overheadLogCleaner alias in composer.json for easy access--days option to keep recent logs--dry-run): Preview changes without modifying files--backup): Create timestamped backups before cleaning
laravel.log.backup.YYYY-MM-DD-HH-MM-SS--level=LEVEL): Keep only specific log levels
--pattern=REGEX): Support for non-standard log formats
--compress): Archive old logs instead of deleting
.gz compressed archiveslaravel.log.old.YYYY-MM-DD-HH-MM-SS.gz--memory-efficient): Handle large log files
Publish configuration file (optional):
php artisan vendor:publish --tag="log-cleaner-config"
Listen to events (optional):
use JiordiViera\LaravelLogCleaner\Events\LogCleaned;
// In EventServiceProvider
protected $listen = [
LogCleaned::class => [LogCleanedListener::class],
];
Use custom exceptions (optional):
use JiordiViera\LaravelLogCleaner\Exceptions\InvalidDaysException;
try {
LogCleaner::clear(days: -1);
} catch (InvalidDaysException $e) {
// Handle error
}
Update the package:
composer require jiordiviera/laravel-log-cleaner:^2.2
(Optional) Publish config to customize defaults:
php artisan vendor:publish --tag="log-cleaner-config"
(Optional) Add event listeners for monitoring
Update composer.json:
composer require jiordiviera/laravel-log-cleaner:^2.0
Ensure PHP 8.1+ and Laravel 9.x+ are installed
No configuration changes needed - all new features are optional
Basic usage remains unchanged:
# These work identically in v1.x and v2.x
php artisan log:clear
php artisan log:clear --days=30
New features are opt-in:
# New v2.x features
php artisan log:clear --days=30 --backup
php artisan log:clear --days=30 --compress
php artisan log:clear --level=ERROR --dry-run
For older PHP or Laravel versions, continue using v1.x:
composer require jiordiviera/laravel-log-cleaner:^1.0
v1.x Support: Security fixes only until 2026-01-01
For detailed information about each release, see the releases page.
How can I help you explore Laravel packages today?