PHPackages                             alkhatibdev/logrotation - 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. alkhatibdev/logrotation

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

alkhatibdev/logrotation
=======================

Laravel package for easy log rotation

1.1.0(6mo ago)6500↓50%MITPHP

Since Oct 12Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/alkhatibdev/logrotation)[ Packagist](https://packagist.org/packages/alkhatibdev/logrotation)[ Docs](https://github.com/alkhatibdev/logrotation)[ RSS](/packages/alkhatibdev-logrotation/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (7)Used By (0)

Laravel Log Rotation Package
============================

[](#laravel-log-rotation-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/150d919d70cb81847b075d0d7bfc6b95f26e3cc57eeb12a517744f499f836d45/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c6b68617469626465762f6c6f67726f746174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alkhatibdev/logrotation)[![Total Downloads](https://camo.githubusercontent.com/7d398760d0f595c5be5a6d25f3daa8c63c1d9ae61d4b5879565291ecd184caf2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c6b68617469626465762f6c6f67726f746174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alkhatibdev/logrotation)[![GitHub Issues](https://camo.githubusercontent.com/36190c8a4bdf2c1264665744ae927ceaa07019c1c9fe34b58d49f80b5fd426e1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f616c6b68617469626465762f6c6f67726f746174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/alkhatibdev/logrotation/issues)

This package makes log file rotation easier by automatically managing and organizing Laravel logs based on **time and file size**, retaining only the most recent logs (e.g., 12 months) and discarding older logs. This solution is ideal for applications that generate high volumes of logs, providing efficient log management and preventing excessive disk usage over time.

Benefits
--------

[](#benefits)

- Rotates your log files **based on date** (monthly) or **file size** (size-based rotation).
- Retains logs for a configurable number of months (default: 12 months), which can be modified through the configuration file.
- Automatically deletes old logs after the configured retention period, freeing up disk space.
- Supports both **compressed (`.gz`)** and uncompressed log files.
- Helps prevent large log files from consuming excessive disk space during high-traffic periods.

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

[](#installation)

Install the package via Composer:

```
composer require alkhatibdev/logrotation
```

Configuration &amp; Advanced Customization
------------------------------------------

[](#configuration--advanced-customization)

You can configure the log rotation behavior either via your .env file or programmatically using the LogRotator class.

### Using .env file

[](#using-env-file)

Set the following variables in your .env file:

```
# Number of months to retain logs (default: 12)
LOG_ROTATION_MAX_MONTHS=12

# Maximum file size (in KB) for size-based rotation (optional, default: null, no size-based rotation)
LOG_ROTATION_MAX_SIZE_KB=10240

# Enable or disable compression for archived logs (optional, default: true)
LOG_ROTATION_COMPRESS=true
```

- `LOG_ROTATION_MAX_MONTHS`: How many months of logs to keep before deletion.
- `LOG_ROTATION_MAX_SIZE_KB`: The size threshold for size-based rotation. When the log file exceeds this, a size-based archive is created.
- `LOG_ROTATION_COMPRESS`: Whether the archived logs should be compressed (`.gz`) or kept uncompressed (`.log`).

**Note:** You can still publish the configuration file if you want to override defaults or use dynamic configuration:

```
php artisan vendor:publish --tag=logrotation
```

### Programmatic Customization

[](#programmatic-customization)

You can fully customize log rotation by using the `LogRotator` class:

```
use AlkhatibDev\LogRotation\LogRotator;

LogRotator::make()
    // Set a custom log file path (default: storage/logs/laravel.log)
    ->setLogFile(storage_path('logs/custom.log'))

    // Set the maximum number of months to retain logs (default: 12)
    ->setMaxMonths(12)

    // Set the maximum file size in KB for size-based rotation (optional) (default: null, no size-based rotation)
    ->setMaxSize(10240) // 10 MB

    // Enable or disable compression for archived logs (.gz) (default: true)
    ->setCompression(true)

    // Perform the rotation immediately
    ->rotate();
```

This merged approach allows you to **configure the package using `.env` for most cases** or **fine-tune behavior programmatically** when needed.

Usage
-----

[](#usage)

### Log Rotation Scheduling

[](#log-rotation-scheduling)

You can schedule log rotation in `routes/console.php`:

```
Artisan::command('logrotation:rotate', function () {
    app('logrotator')->rotate();
})->daily();
```

Or for **Laravel 10.x** and below, in `app/Console/Kernel.php`:

```
protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {
        app('logrotator')->rotate();
    })->daily();
}
```

**How it works:**

- Scheduling **daily** ensures **size-based rotation** works properly, rotating large log files as soon as they exceed the configured size.
- Monthly rotation will still run **only once per month** — if the current month has already been rotated, it will be ignored until the next month.
- **Optional:** If you don’t want to enable size-based rotation, you can run the command `monthly()` instead. This will rotate logs **only once per month** based on time, ignoring size increasing during the month.

### Monthly Log Archives

[](#monthly-log-archives)

The rotation creates a **timestamped archive** for the current file:

```
file-YYYY-MM-monthly.log
file-YYYY-MM-monthly.log.gz (if compression is enabled)

```

### Size-Based Log Rotation

[](#size-based-log-rotation)

The package now supports automatic rotation **when the log file exceeds a specified size**. This is useful for high-traffic applications where a single month’s log may grow too large.

The rotation creates a **timestamped archive** for the current file:

```
file-YYYY-MM_DD-HH-MM-SS-size.log
file-YYYY-MM_DD-HH-MM-SS-size.log.gz (if compression is enabled)

```

Size-based logs are also subject to **month-based retention** and will be deleted if their month is older than the configured `max_months`.

Support
-------

[](#support)

If you encounter any issues or have feature requests, feel free to [open an issue](https://github.com/alkhatibdev/logrotation/issues) on GitHub.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance66

Regular maintenance activity

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~189 days

Total

3

Last Release

205d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a98ee8122409e21e0d095bde2b1d5b6541ff0c18a693a9e7f2828b5ee76eecd?d=identicon)[alkhatibdev](/maintainers/alkhatibdev)

---

Top Contributors

[![alkhatibdev](https://avatars.githubusercontent.com/u/20454989?v=4)](https://github.com/alkhatibdev "alkhatibdev (16 commits)")

---

Tags

loglaravelrotatelogrotation

### Embed Badge

![Health badge](/badges/alkhatibdev-logrotation/health.svg)

```
[![Health](https://phpackages.com/badges/alkhatibdev-logrotation/health.svg)](https://phpackages.com/packages/alkhatibdev-logrotation)
```

###  Alternatives

[ytake/laravel-fluent-logger

fluent logger for laravel and lumen

63541.6k1](/packages/ytake-laravel-fluent-logger)[kitloong/laravel-app-logger

Laravel log for your application

101.2M8](/packages/kitloong-laravel-app-logger)[moesif/moesif-laravel

Moesif Collection/Data Ingestion Middleware for Laravel

1065.8k](/packages/moesif-moesif-laravel)[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)
