Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Log Cleaner Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Run composer require jiordiviera/laravel-log-cleaner to install. The package adds a single Artisan command: log:clear. For immediate use, run php artisan log:clear to clear all logs. For a production-safe first test, use php artisan log:clear --dry-run to preview what would be deleted without making changes.

Key starting points:

  • Basic command: php artisan log:clear (clears all logs)
  • Dry-run mode: --dry-run (safe testing)
  • Programmatic usage: LogCleaner::clearAll() facade method

Implementation Patterns

Daily Maintenance Workflow

# Weekly cleanup (30-day retention)
php artisan log:clear --days=30 --backup --compress

# Monthly archive (90-day retention)
php artisan log:clear --days=90 --backup --compress --level=ERROR

CI/CD Integration

# In deployment scripts
php artisan log:clear --days=7 --no-events --memory-efficient

Log Rotation Strategy

# Rotate logs with retention policy
php artisan log:clear --days=14 --backup --compress --level=WARNING

Programmatic Integration

// In scheduled tasks
LogCleaner::clearOld(7, backup: true, compress: true);

// In custom commands
$cleaner = app(LogCleaner::class);
$cleaner->clearWithBackup(30);

Configuration-Driven Cleanup

// In service providers
app(LogCleaner::class)->clear(config('log.retention_days'));

Gotchas and Tips

Common Pitfalls

  1. File Locking Conflicts: Disable with --no-lock if running in environments where file locks may cause issues
  2. Memory Limits: Use --memory-efficient for large log files (>100MB)
  3. Backup Space: Ensure min_free_disk_space_mb is configured appropriately
  4. Log Level Filtering: Remember --level=ERROR keeps only ERROR logs (removes all others)

Debugging Tips

  • Use --dry-run to verify operations before execution
  • Check storage/logs/laravel.log.backup-*.gz for compressed backups
  • Review events with php artisan event:listen JiordiViera\LaravelLogCleaner\Events\*

Configuration Quirks

  • Set backup['enabled'] = false to disable backups completely
  • Adjust memory_threshold for environments with constrained memory
  • Configure locking['enabled'] = false for scripted operations

Extension Points

  1. Custom Events: Listen to LogCleaning/LogCleaned for audit logging
  2. Pre-Cleanup Validation: Add middleware to LogCleaning event
  3. Post-Cleanup Actions: Dispatch notifications via LogCleaned event
  4. Custom Log Parsers: Extend the pattern matching for non-standard log formats

Performance Considerations

  • For very large logs (>500MB), always use --memory-efficient
  • Schedule cleanup during low-traffic periods
  • Consider compressing backups immediately with --compress

Security Notes

  • Restrict command access via Laravel's authorization system
  • Validate backup locations in config/log-cleaner.php
  • Monitor disk space requirements for backup operations
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope