New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

jiordiviera/laravel-log-cleaner

A Laravel package to easily clean the log files.
3,727 9

Larablocks Analysis

jiordiviera/laravel-log-cleaner works with Laravel 10 to 13 (latest release v2.4.0, Nov 18, 2026).

Laravel 7, 8 and 9 in earlier releases.

Promising: maintained and up to date, meets 2 of 4 checks; not yet widely used.

  • Works with Laravel 13, the current version
  • Released in the last 12 months (Nov 18, 2026)
  • 144 downloads a month (needs 10,000)
  • 9 GitHub stars (needs 100)

State

Actively maintained
  • Last stable release: Nov 18, 2026.
  • 4 releases in the last 12 months.
  • First released: Oct 6, 2024.
  • Monthly downloads: 144.
  • 7 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 30, 2026.

Install
composer require jiordiviera/laravel-log-cleaner
Latest Version:v2.4.0
PHP:^8.2
Laravel:10 – 13
Older releases:7 · 8 · 9
License:MIT
Last Updated:Nov 23, 2026
Links: GitHub  ·  Packagist
Maintainer: jiordiviera
Laravel Log Cleaner — simple, safe log management for Laravel

Clean up Laravel logs safely, without the clutter.

Packagist version Downloads Tests MIT license

Laravel Log Cleaner is a lightweight Laravel package that removes old log entries using an Artisan command. Preview changes first, keep backups, compress removed entries and handle large files using streaming.

Installation

composer require jiordiviera/laravel-log-cleaner

Requirements: PHP 8.2+ and Laravel 10–13. Laravel 13 requires PHP 8.3+. Actual compatibility also depends on the framework's PHP requirements. See Packagist for older releases.

Quick start

# Remove all logs
php artisan log:clear

# Remove entries older than 30 days
php artisan log:clear --days=30

# Preview changes without modifying files
php artisan log:clear --days=30 --dry-run

# Create a backup before cleaning
php artisan log:clear --days=30 --backup

Features

  • Safe cleanup: dry-run, cooperative file locking, backups and checks before replacing files.
  • Targeted retention: choose age, log level, custom date pattern or a specific file.
  • Compression: save removed entries in a gzip archive.
  • Large files: stream data to reduce peak memory use.
  • Health report: log:stats shows size, records per level and date range, and can fail above a size limit.
  • Scheduling: optional automatic log:clear through Laravel's scheduler.
  • Integrations: Laravel facade, configurable defaults and lifecycle events.

Why and how it is built

Deleting logs by hand on a production server is tedious and easy to get wrong: you can remove entries you still need, or replace a file while the application is writing to it. This package turns that chore into a repeatable command, built around a few deliberate choices:

  • One core, several entry points. The cleaning logic lives in a single service. The Artisan command, the scheduler and the facade all call it, so a cleanup behaves the same however it is triggered.
  • Streaming above a memory threshold. Files larger than memory_threshold (50 MB by default), or any file with --memory-efficient, are read line by line, so memory use stays flat whatever the log size. Smaller files take the simpler in-memory path.
  • Never edit a log in place. Kept entries are written to a temporary file next to the original, the original is checked for changes, then the temporary file replaces it with rename(). With --dry-run and --backup, you can see and keep everything before anything is removed.
  • Cooperative locking. Each file gets a non-blocking flock() lock, so two cleanups (for example the scheduler and a manual run) never process the same file at once. The trade-off: the lock does not block the application's own log writers (see Important limitations).
  • Events instead of built-in side effects. LogCleaning, LogFileCleaned and LogCleaned let you add alerts, audit trails or metrics without changing the package.

Command options

Option Purpose
--days=30 Remove entries older than 30 days
--dry-run Preview cleanup without writing
--backup Back up a log before modifying it
--compress Archive removed entries as gzip
--level=ERROR Filter by log level
--pattern=REGEX Use a custom date pattern
--file=laravel.log Select one log file
--memory-efficient Force streaming mode
--no-lock Disable cooperative cleanup locking
--no-events Disable cleanup events

For example:

php artisan log:clear --days=7 --backup --compress
php artisan log:clear --days=30 --file=laravel.log --dry-run
php artisan log:clear --days=0 --level=ERROR

Log health report

log:stats is read-only: it streams each log file and reports its size, records per level, and the oldest and newest record dates, plus the backups and archives left by earlier cleanups.

php artisan log:stats
php artisan log:stats --file=laravel.log
php artisan log:stats --json
php artisan log:stats --max-size=500   # exit code 1 above 500 MB, for monitoring

Stack trace lines are not counted as records. The size limit can also be set with health.max_size_mb (or LOG_CLEANER_MAX_SIZE_MB).

Scheduled cleaning

The package can register log:clear in Laravel's scheduler for you. Enable it in config/log-cleaner.php (or with LOG_CLEANER_SCHEDULE_ENABLED=true):

'schedule' => [
    'enabled' => true,
    'cron' => '0 2 * * *',      // every day at 02:00
    'timezone' => null,
    'options' => ['days' => 30, 'backup' => false, 'compress' => true],
],

Your server still needs Laravel's usual schedule:run cron entry (or php artisan schedule:work). Check the registration with php artisan schedule:list.

Programmatic usage

use JiordiViera\LaravelLogCleaner\LogCleanerFacade as LogCleaner;

LogCleaner::clearAll();
LogCleaner::clearOld(30);
LogCleaner::clearWithBackup(30);
LogCleaner::clearWithCompression(30);

LogCleaner::clear(
    days: 30,
    backup: true,
    compress: true,
    file: 'laravel.log'
);

Configuration

Publish the optional configuration file:

php artisan vendor:publish --tag="log-cleaner-config"

You can adjust the memory threshold, backup retention, compression level, default log level, file-lock timeout, event dispatching, scheduled cleaning and the health size limit in config/log-cleaner.php.

Events and exceptions

Listen to these events to observe cleanup:

  • LogCleaning — before cleanup starts.
  • LogFileCleaned — after a file has been cleaned.
  • LogCleaned — after cleanup completes.

The package also provides dedicated exceptions for invalid parameters, permissions, disk space, backups, locking and compression. See the classes in src/Exceptions.

Development

composer install
composer test
composer analyse
composer lint

Tests use Pest; formatting uses Laravel Pint; static analysis runs PHPStan level 4. The CI matrix covers PHP 8.2/8.3 with Laravel 10–12, plus PHP 8.3 with Laravel 13.

Important limitations

  • Concurrent writers: locks coordinate participating cleanup processes, not unrelated log writers. A write between the final integrity check and replacement may still race.
  • Multiline logs: continuation lines follow the last recognized log header. Unrecognized, undated content may be retained.
  • Disk space: streaming and backups still need free space for temporary files and archives.
  • Compression: requires PHP's zlib extension.

Releases and contributions

Changes merged into main are not necessarily published on Packagist. See the changelog for release history and unreleased changes.

Issues and pull requests are welcome in the GitHub repository.

Released under the MIT License.

Alternatives to jiordiviera/laravel-log-cleaner

rap2hpoutre/laravel-log-viewer

A Laravel log reader

16,981,969 3,193
ytake/laravel-fluent-logger

fluent logger for laravel and lumen

567,198 62
mitydigital/statamic-logger

Detailed, customisable and human-friendly logging for Statamic.

18,164 2
hedii/artisan-log-cleaner

An artisan command to clear laravel log files

74,314 41
emotality/laravel-telegram-logger

Laravel package to report exceptions to a Telegram chat, group or channel.

14,174 2

Version History

Version Released PHP Laravel License
v2.4.0 ^8.2 ^10.0 || ^11.0 || ^12.0 || ^13.0 MIT
v2.3.0 ^8.2 ^10.0 || ^11.0 || ^12.0 || ^13.0 MIT
2.2.0 ^8.2|^8.3 ^10.0|^11.0|^12.0|^13.0 MIT
2.1.0 ^8.1|^8.2|^8.3 ^9.0|^10.0|^11.0|^12.0 MIT
v2.0.1 ^8.1|^8.2|^8.3 ^9.0|^10.0|^11.0|^12.0 MIT