PHPackages                             jiordiviera/laravel-log-cleaner - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. jiordiviera/laravel-log-cleaner

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

jiordiviera/laravel-log-cleaner
===============================

A Laravel package to easily clean the log files.

2.2.0(1mo ago)52.0k↓25%1MITPHPPHP ^8.2|^8.3CI failing

Since Oct 6Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/jiordiviera/laravel-log-cleaner)[ Packagist](https://packagist.org/packages/jiordiviera/laravel-log-cleaner)[ RSS](/packages/jiordiviera-laravel-log-cleaner/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (12)Versions (14)Used By (0)

```
██╗      █████╗ ██████╗  █████╗ ██╗   ██╗███████╗██╗
██║     ██╔══██╗██╔══██╗██╔══██╗██║   ██║██╔════╝██║
██║     ███████║██████╔╝███████║██║   ██║█████╗  ██║
██║     ██╔══██║██╔══██╗██╔══██║╚██╗ ██╔╝██╔══╝  ██║
███████╗██║  ██║██║  ██║██║  ██║ ╚████╔╝ ███████╗███████╗
╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝  ╚═══╝  ╚══════╝╚══════╝

██╗      ██████╗  ██████╗
██║     ██╔═══██╗██╔════╝
██║     ██║   ██║██║  ███╗
██║     ██║   ██║██║   ██║
███████╗╚██████╔╝╚██████╔╝
╚══════╝ ╚═════╝  ╚═════╝

 ██████╗██╗     ███████╗ █████╗ ███╗   ██╗███████╗██████╗
██╔════╝██║     ██╔════╝██╔══██╗████╗  ██║██╔════╝██╔══██╗
██║     ██║     █████╗  ███████║██╔██╗ ██║█████╗  ██████╔╝
██║     ██║     ██╔══╝  ██╔══██║██║╚██╗██║██╔══╝  ██╔══██╗
╚██████╗███████╗███████╗██║  ██║██║ ╚████║███████╗██║  ██║
 ╚═════╝╚══════╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═══╝╚══════╝╚═╝  ╚═╝

```

 [![Latest Stable Version](https://camo.githubusercontent.com/47293b311d1a8341d98cfe844c0f99a5640731b9adf333cedd706d7cdcddff13/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a696f72646976696572612f6c61726176656c2d6c6f672d636c65616e65723f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/jiordiviera/laravel-log-cleaner) [![Total Downloads](https://camo.githubusercontent.com/3d195c2e4e9c512323b387820949d9e110003801bffb4f501010370a11d26b20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a696f72646976696572612f6c61726176656c2d6c6f672d636c65616e65723f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/jiordiviera/laravel-log-cleaner) [![Latest Unstable Version](https://camo.githubusercontent.com/c3eed65d90f84c10dc6591df7dd02f1cb5c5bfa1ce42eebefb0ea59bdc2a5758/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a696f72646976696572612f6c61726176656c2d6c6f672d636c65616e65723f696e636c7564655f70726572656c6561736573267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/jiordiviera/laravel-log-cleaner) [![License](https://camo.githubusercontent.com/1557c5b5df788be9b64fe0b04c18ea1c6a609d9cd6c11b20f1d6c5204e063238/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a696f72646976696572612f6c61726176656c2d6c6f672d636c65616e65723f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/jiordiviera/laravel-log-cleaner) [![Tests Status](https://github.com/jiordiviera/laravel-log-cleaner/actions/workflows/tests.yml/badge.svg)](https://github.com/jiordiviera/laravel-log-cleaner/actions/workflows/tests.yml)

**Laravel Log Cleaner** is a utility package designed for the efficient management of Laravel log files. It allows developers to quickly clear log data using an Artisan command, enhancing application performance and management. This tool is compatible with Laravel versions 7, 8, 9, 10, and 11.

Installation
------------

[](#installation)

You can install the package via **Composer** by executing the following command:

```
composer require jiordiviera/laravel-log-cleaner
```

Compatibility
-------------

[](#compatibility)

### Version 2.x (Current)

[](#version-2x-current)

**PHP Requirements:**

- PHP 8.1+
- PHP 8.2+
- PHP 8.3+

**Laravel Support:**

- Laravel 9.x
- Laravel 10.x
- Laravel 11.x
- Laravel 12.x

### Version 1.x (Legacy)

[](#version-1x-legacy)

For older PHP versions, use version 1.x:

- PHP 7.0+ to 8.2
- Laravel 7.x to 11.x

```
composer require jiordiviera/laravel-log-cleaner:^1.0
```

Usage
-----

[](#usage)

After installation, an Artisan command is available to clear the Laravel log file with advanced options:

### Basic Usage

[](#basic-usage)

1. **Clear all logs:**

    ```
    php artisan log:clear
    ```
2. **Clear logs older than specific days:**

    ```
    php artisan log:clear --days=30
    ```

### Advanced Features (v2.0+)

[](#advanced-features-v20)

#### 🔒 Safe Operations

[](#-safe-operations)

```
# Preview what would be deleted (dry run)
php artisan log:clear --days=30 --dry-run

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

#### 🎯 Targeted Cleaning

[](#-targeted-cleaning)

```
# Keep only ERROR level logs
php artisan log:clear --days=0 --level=ERROR

# Clean with custom date pattern
php artisan log:clear --days=30 --pattern="/^(\d{4}-\d{2}-\d{2})/"

# Clean only specific log file
php artisan log:clear --days=30 --file=laravel.log
```

#### 📦 Compression &amp; Memory

[](#-compression--memory)

```
# Compress old logs instead of deleting
php artisan log:clear --days=30 --compress

# Force memory-efficient processing for large files
php artisan log:clear --days=30 --memory-efficient
```

#### 🚀 Combined Options

[](#-combined-options)

```
# Complete workflow with all safety features
php artisan log:clear --days=30 --backup --compress --level=ERROR --dry-run
```

### Programmatic Usage with Facade

[](#programmatic-usage-with-facade)

You can also use the `LogCleaner` facade to clear logs programmatically in your code:

```
use JiordiViera\LaravelLogCleaner\LogCleanerFacade as LogCleaner;

// Clear all logs
LogCleaner::clearAll();

// Clear logs older than 30 days
LogCleaner::clearOld(30);

// Clear with backup
LogCleaner::clearWithBackup(30);

// Clear with compression
LogCleaner::clearWithCompression(30);

// Clear only specific file
LogCleaner::clearOld(30, 'laravel.log');

// Advanced usage with all options
LogCleaner::clear(
    days: 30,
    backup: true,
    compress: true,
    level: 'ERROR',
    pattern: '/^(\d{4}-\d{2}-\d{2})/',
    memoryEfficient: true,
    file: 'laravel.log'
);
```

### Available Options

[](#available-options)

OptionDescriptionExample`--days=N`Keep logs from last N days`--days=30``--backup`Create backup before cleaning`--backup``--dry-run`Preview changes without applying`--dry-run``--level=LEVEL`Filter by log level (ERROR, WARNING, INFO, DEBUG)`--level=ERROR``--pattern=REGEX`Custom date pattern matching`--pattern="/^(\d{4}-\d{2}-\d{2})/"``--compress`Compress old logs instead of deleting`--compress``--memory-efficient`Force memory-efficient processing`--memory-efficient``--file=FILENAME`Clean only specific log file`--file=laravel.log`### Examples

[](#examples)

- **Clear all logs:**

    ```
    $ php artisan log:clear
    Log file cleared successfully.
    ```
- **Clear logs older than 30 days:**

    ```
    $ php artisan log:clear --days=30
    Logs older than 30 days have been removed.
    ```
- **Preview changes (dry run):**

    ```
    $ php artisan log:clear --days=30 --dry-run
    [DRY RUN] Would remove 150 lines from laravel.log
    [DRY RUN] Estimated space to free: 45.2 MB
    ```
- **Create backup and compress:**

    ```
    $ php artisan log:clear --days=30 --backup --compress
    Backup created: /path/to/laravel.log.backup.2025-07-18-14-30-15
    Logs compressed to: laravel.log.old.2025-07-18-14-30-15.gz
    Logs older than 30 days have been removed.
    ```

Configuration
-------------

[](#configuration)

No additional configuration is necessary. The `log:clear` command is immediately available upon package installation.

What's New in v2.0
------------------

[](#whats-new-in-v20)

### 🚀 Performance &amp; Memory Optimizations

[](#-performance--memory-optimizations)

- **Memory-efficient processing** for large log files (&gt;50MB)
- **Automatic memory threshold detection** prevents out-of-memory errors
- **Stream processing** handles multi-GB log files without memory issues
- **Regex pattern caching** improves performance on repeated operations

### 🔒 Enhanced Safety &amp; Robustness

[](#-enhanced-safety--robustness)

- **Pre-flight permission validation** prevents runtime errors
- **Backup creation** with timestamp for data recovery
- **Dry-run mode** for safe preview of operations
- **Enhanced error handling** with detailed reporting

### 🎯 Advanced Filtering

[](#-advanced-filtering)

- **Log level filtering** (ERROR, WARNING, INFO, DEBUG, etc.)
- **Custom date patterns** for non-standard log formats
- **Flexible date range selection** with improved accuracy

### 📦 Archive &amp; Compression

[](#-archive--compression)

- **Compression support** for old logs instead of deletion
- **Automatic cleanup** of temporary files
- **Space-efficient archiving** with gzip compression

### 🔧 Breaking Changes

[](#-breaking-changes)

- **Minimum PHP version:** 8.1+ (dropped PHP 7.x support)
- **Minimum Laravel version:** 9.x+ (dropped Laravel 7.x-8.x support)
- **Enhanced command signature** with new options

### 📊 Performance Benchmarks

[](#-performance-benchmarks)

- Handles **1GB+ log files** without memory issues
- **50%+ performance improvement** on large file operations
- **Zero memory leaks** with proper resource management
- **Concurrent processing** support for multiple log files

Running Tests
-------------

[](#running-tests)

This package uses **Pest** for testing. You can run tests with the following command:

```
./vendor/bin/pest
```

Ensure your tests are organized correctly within the `tests/` directory.

Contributing
------------

[](#contributing)

Contributions are welcomed! Feel free to submit **Issues** or **Pull Requests** on [GitHub](https://github.com/jiordiviera/laravel-log-cleaner).

### Development Workflow

[](#development-workflow)

For contributors:

1. **Clone the repository:**

    ```
    git clone https://github.com/jiordiviera/laravel-log-cleaner.git
    ```
2. **Install dependencies:**

    ```
    composer install
    ```
3. **Run tests:**

    ```
    ./vendor/bin/pest
    ```

About
-----

[](#about)

This package was created to streamline the management of log files in Laravel applications. Instead of manually clearing the log files, you can achieve this efficiently with a single command, with the option to selectively remove older logs.

License
-------

[](#license)

The Laravel Log Cleaner is open-source software licensed under the [MIT License](https://opensource.org/licenses/MIT).

---

> **Note:** Initially developed for Laravel 11, this package remains compatible with earlier versions (7, 8, 9, 10).

For further information, visit the [GitHub repository](https://github.com/jiordiviera/laravel-log-cleaner).

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance84

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 96.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~67 days

Recently: every ~76 days

Total

9

Last Release

46d ago

Major Versions

v1.0.4 → v2.0.02025-07-18

PHP version history (4 changes)v1.0.0PHP ^8.0

v1.0.3PHP ^7.0|^8.0|^8.1|^8.2

v2.0.0PHP ^8.1|^8.2|^8.3

2.2.0PHP ^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/809a4ada50fc54fe02b1956bc85fbf9e403f3a8de208faf27dc5fd19b84d4035?d=identicon)[jiordiviera](/maintainers/jiordiviera)

---

Top Contributors

[![jiordiviera](https://avatars.githubusercontent.com/u/157500676?v=4)](https://github.com/jiordiviera "jiordiviera (147 commits)")[![karimalik](https://avatars.githubusercontent.com/u/40320510?v=4)](https://github.com/karimalik "karimalik (6 commits)")

---

Tags

loglaravelloggingartisanlaravel-packagemaintenancecleanerlog fileslog management

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jiordiviera-laravel-log-cleaner/health.svg)

```
[![Health](https://phpackages.com/badges/jiordiviera-laravel-log-cleaner/health.svg)](https://phpackages.com/packages/jiordiviera-laravel-log-cleaner)
```

###  Alternatives

[sentry/sentry-laravel

Laravel SDK for Sentry (https://sentry.io)

1.3k114.3M154](/packages/sentry-sentry-laravel)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[ytake/laravel-fluent-logger

fluent logger for laravel and lumen

63541.6k1](/packages/ytake-laravel-fluent-logger)[hedii/artisan-log-cleaner

An artisan command to clear laravel log files

4161.6k](/packages/hedii-artisan-log-cleaner)[melihovv/laravel-log-viewer

A Laravel log viewer

1231.5k1](/packages/melihovv-laravel-log-viewer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
