ndarproj / laravel-logzip
Compress your laravel logs into a zip file with just one command
Requires
- php: ^7.2 | ^8.0
- illuminate/config: ^6.0|^7.0|^8.0
- illuminate/console: ^6.0|^7.0|^8.0
- illuminate/log: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
- monolog/monolog: ^2.0
README
This package allows you to compress or zip laravel logs with just one command.
Installation
This package can be used in Laravel 5 or higher.
You can install the package via composer:
composer require ndarproj/laravel-logzip
- run this command if ever you encounter this error - Fatal error: Allowed memory size of 1610612736
composer self-update --2
Usage / Command
To compress all .log files inside the storage/logs folder run:
php artisan log:zip
Schedule / Automate laravel log compression / zip with PM2
Install pm2 with NPM. You can download NPM HERE
npm install pm2 -g
Download this FILE and place it inside your laravel root folder or create a new file and copy this code
module.exports = { apps: [ { name: 'log-zip', interpreter: 'php', script: 'artisan', args: 'log:zip', watch: false, cron: '0 * * * *', // this would zip your logs hourly autorestart: false, } ] };
Update cron field to change the schedule. Reference: https://crontab.guru
To run pm2
pm2 start logzip.config.js #if you created your own file pm2 start <filename>
Configuration
If you need to change the name or allow deletion after compression, you can modify the config file.
You can publish config file with:
php artisan vendor:publish --provider="Ndarproj\\Logzip\\LogzipServiceProvider" --tag=config
This is the contents of the published config/rotate.php config file:
<?php return [ /* |-------------------------------------------------------------------------- | Filename |-------------------------------------------------------------------------- | | This option defines what should be the compressed logs output filename. | */ 'log_zip_filename' => 'laravel', /* |-------------------------------------------------------------------------- | Compression Enable |-------------------------------------------------------------------------- | | This option defines if the logs must be compressed. | set value to false to disable */ 'log_compress_files' => true, /* |-------------------------------------------------------------------------- | Delete Enable |-------------------------------------------------------------------------- | | This option defines if the logs should be deleted after being compressed. | set value to true to enable */ 'log_delete' => true, ];
Contributing
Any contributions are welcome.
License
The MIT License (MIT). Please see License File for more information.