cesargb/laravel-logs-rotate is a Laravel package for rotate files log with compression.
It currently has 26 GitHub stars and 69.114 downloads on Packagist (latest version 2.9.0).
Install it with composer require cesargb/laravel-logs-rotate.
Discover more Laravel packages by cesargb
or browse all Laravel packages to compare alternatives.
Last updated
This package allows you to rotate the Laravel record file with compression. This method is useful if you use logger channel single (StreamHandler)
You can install the package via composer:
composer require cesargb/laravel-logs-rotate
At this moment, every day at 00:00 your application executes a schedule to rotate the Laravel record files.
If you need to change the frequency or another function, you can modify the config file.
You can publish config file with:
php artisan vendor:publish --provider="Cesargb\LaravelLog\RotateServiceProvider" --tag=config
This is the contents of the published config/rotate.php config file:
<?php
return [
/*
|--------------------------------------------------------------------------
| Compression Enable
|--------------------------------------------------------------------------
|
| This option defines if the file rotated must be compressed.
| If you prefer not compress file, set this value at false.
*/
'log_compress_files' => true,
/*
|--------------------------------------------------------------------------
| Schedule Rotate
|--------------------------------------------------------------------------
|
| Determine when must be run the cron.
| You can disable the schedule change the option enable at false.
| You can change the frequency with option cron.
|
*/
'schedule' => [
'enable' => true,
'cron' => '0 0 * * *',
],
/*
|--------------------------------------------------------------------------
| Max Files Rotated
|--------------------------------------------------------------------------
|
| This value determine the max number of files rotated in the archive folder.
|
*/
'log_max_files' => env('LOG_MAX_FILES', 30),
/*
|--------------------------------------------------------------------------
| Minimum Log File Size
|--------------------------------------------------------------------------
|
| This value determines the minimum size (in bytes) that a log file must
| have before it can be rotated. Files smaller than this size will not
| be rotated. Set to 0 to disable this check and rotate regardless of size.
|
*/
'log_min_size' => env('LOG_MIN_SIZE', 0),
/*
|--------------------------------------------------------------------------
| Truncate Log file
|--------------------------------------------------------------------------
|
| This option defines if the log file must be truncated after rotated.
| If you prefer not truncate file, set this value at false.
*/
'truncate' => env('LOG_TRUNCATE', true),
/*
|--------------------------------------------------------------------------
| Other files to rotated
|--------------------------------------------------------------------------
|
| Array the other foreign files
|
| Example:
| 'foreign_files' => [
storage_path('/logs/worker.log')
| ]
|
*/
'foreign_files' => []
];
If you are using monolog/monolog:^3.10 or higher, you can disable the truncate option for more efficient log rotation:
'truncate' => false,
With Monolog 3.10+, the rotation process is optimized and truncating is no longer necessary, resulting in better performance. For more details, see monolog PR #1963.
You have a command to rotate other files, rotate:files
php artisan rotate:files --help
Description:
Rotate files
Usage:
rotate:files [options]
Options:
-f, --file[=FILE] Files to rotate (multiple values allowed)
-c, --compress[=COMPRESS] Compress the file rotated [default: "true"]
-m, --max-files[=MAX-FILES] Max files rotated [default: "5"]
-d, --dir[=DIR] Dir where archive the file rotated
Every time a file is rotated one of these events occurs:
Cesargb\LaravelLog\Events\RotateWasSuccessful
This event will be fired when rotated was successful.
It has two public properties:
Cesargb\LaravelLog\Events\RotativeHandler
This event will be fired when an error occurs while rotated
It has two public properties:
You can only rotate the logs file was generate with logger channel StreamHandler.
Run test with:
composer test
Please see UPGRADING for details.
Any contributions are welcome.
The MIT License (MIT). Please see License File for more information.