Skip to content

cesargb/php-log-rotation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP class to logs rotation

PHP Class to rotate log files

This class permit log rotating with diferetne processor.

tests Latest Version on Packagist

Installation

You can install this package via composer using:

composer require cesargb/php-log-rotation

Usage

This is an example:

use Cesargb\Log\Rotation;
use Cesargb\Log\Processors\GzProcessor;
use Cesargb\Log\Processors\RotativeProcessor;

$fileLog='file.log';
$fileMaxSize=50; // only rotate log if over 50MB

$rotation = new Rotation();

$rotation->addProcessor(new GzProcessor());
    ->addProcessor(new RotativeProcessor())
    ->rotate($fileLog, $fileMaxSize);

Processor

After of move the content of current log file, you can process changes in the file was rotated.

GzProcessor

This processor permit compress in gz format the file rotated.

RotativeProcessor

This processor permit rotative each file in format file.log.1, file.log.2, ...

You can call method setMaxFiles to set the number max of the files rotated. By default is 366 (One year if rotate each day).

Todo

[ ] Processor Prefix; To add prefix to file rotated, sample: date (yyyy-mm-dd) [ ] Processor Archive; To move the file rotated to other dir. [ ] Processors to move to the cloud

Test

Run test with:

composer test

Contributing

Any contributions are welcome.