uwakmfon1/laravel-logs-cleanup

A Laravel package for cleaning old log files automatically.

Maintainers

Package info

github.com/Uwakmfon1/laravel-logs-cleanup

Homepage

pkg:composer/uwakmfon1/laravel-logs-cleanup

Fund package maintenance!

Uwakmfon1

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-05-24 03:18 UTC

This package is auto-updated.

Last update: 2026-05-24 03:32:57 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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:

  1. Reads laravel.log line-by-line
  2. Detects log timestamps
  3. Removes entries older than the cutoff date
  4. Writes valid logs into a temporary file
  5. 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.