PHPackages                             cesargb/php-log-rotation - 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. cesargb/php-log-rotation

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

cesargb/php-log-rotation
========================

PHP Class to rotate log files

2.8.0(2mo ago)19321.7k↓33.2%8[2 issues](https://github.com/cesargb/php-log-rotation/issues)4MITPHPPHP ^8.0CI passing

Since Dec 7Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/cesargb/php-log-rotation)[ Packagist](https://packagist.org/packages/cesargb/php-log-rotation)[ Docs](https://github.com/cesargb/php-log-rotation)[ RSS](/packages/cesargb-php-log-rotation/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (4)Versions (23)Used By (4)

PHP class to logs rotation
==========================

[](#php-class-to-logs-rotation)

This PHP package allows you to rotate a log file and compress it.

[![tests](https://github.com/cesargb/php-log-rotation/workflows/tests/badge.svg)](https://github.com/cesargb/php-log-rotation/actions)[![phpstan](https://github.com/cesargb/php-log-rotation/actions/workflows/phpstan.yml/badge.svg)](https://github.com/cesargb/php-log-rotation/actions/workflows/phpstan.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/3a0cf103246d7c28ff1de709ab7f62a0d95afdc933595a06f3443d522ad1feaa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636573617267622f7068702d6c6f672d726f746174696f6e2e7376673f7374796c653d666c61742d73717561726526636f6c6f723d627269676874677265656e)](https://packagist.org/packages/cesargb/php-log-rotation)[![Total Downloads](https://camo.githubusercontent.com/9e974f87a655a36802da02df1f0d41ec0d5fccad9aa17cd543ca95d99756f0bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636573617267622f7068702d6c6f672d726f746174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cesargb/php-log-rotation)

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

[](#installation)

You can install this package via composer using:

```
composer require cesargb/php-log-rotation
```

Usage
-----

[](#usage)

```
use Cesargb\Log\Rotation;
use Cesargb\Log\Exceptions\RotationFailed;

$rotation = new Rotation();

$rotation
    ->compress() // Optional, compress the file after rotated. Accept level compression argument.
    ->files(30) // Optional, files are rotated 30 times before being removed. Default 366
    ->minSize(1024) // Optional, are rotated when they grow bigger than 1024 bytes. Default 0
    ->truncate() // Optional, truncate the original log file in place after creating a copy, instead of moving the old log file.
    ->then(function ($filenameTarget, $filenameRotated) {}) // Optional, to get filename target and original filename
    ->catch(function (RotationFailed $exception) {}) // Optional, to catch a exception in rotating
    ->finally(function ($message, $filenameTarget) {}) // Optional, this method will be called when the process has finished
    ->rotate('file.log');
```

Or you can define the options in the constructor

```
use Cesargb\Log\Rotation;
use Cesargb\Log\Exceptions\RotationFailed;

$rotation = new Rotation([
    'files' => 1,
    'compress' => true, // Set level compression or true to default level. Default false
    'min-size' => 10,
    'truncate' => false,
    'then' => function ($filename) {},
    'catch' => function (RotationFailed $exception) {},
    'finally' => function ($message, $filename) {},
]);

$rotation->rotate('file.log');
```

Example: Using with crontab
---------------------------

[](#example-using-with-crontab)

To automatically rotate your logs every day at 12:01 AM, add the following line to your crontab:

```
1 0 * * * /usr/bin/php /path/to/your/log-rotation-script.php
```

Test
----

[](#test)

Run test with:

```
composer test
```

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

[](#contributing)

Any contributions are welcome.

###  Health Score

59

—

FairBetter than 98% of packages

Maintenance83

Actively maintained with recent releases

Popularity46

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% 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 ~130 days

Recently: every ~386 days

Total

16

Last Release

74d ago

Major Versions

1.2.0 → 2.0.02021-03-22

PHP version history (3 changes)1.0.0PHP ^7.3 || ^8.0

2.0.0PHP ^7.4 || ^8.0

2.7.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25681494?v=4)[Cesar Garcia](/maintainers/cesargb)[@cesargb](https://github.com/cesargb)

---

Top Contributors

[![cesargb](https://avatars.githubusercontent.com/u/25681494?v=4)](https://github.com/cesargb "cesargb (90 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![johnpipi](https://avatars.githubusercontent.com/u/14940?v=4)](https://github.com/johnpipi "johnpipi (3 commits)")[![gnovaro](https://avatars.githubusercontent.com/u/270990?v=4)](https://github.com/gnovaro "gnovaro (1 commits)")

---

Tags

compressedlogphprotationlogphprotation

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cesargb-php-log-rotation/health.svg)

```
[![Health](https://phpackages.com/badges/cesargb-php-log-rotation/health.svg)](https://phpackages.com/packages/cesargb-php-log-rotation)
```

###  Alternatives

[opengento/module-webapi-logger

This module allows you to analyze all the webapi rest done call toward your Magento.

1118.1k](/packages/opengento-module-webapi-logger)

PHPackages © 2026

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