PHP Class to rotate log files
This class permit log rotating with diferetne processor.
You can install this package via composer using:
composer require cesargb/php-log-rotation
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);
After of move the content of current log file, you can process changes in the file was rotated.
This processor permit compress in gz format the file rotated.
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).
[ ] 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
Run test with:
composer test
Any contributions are welcome.