PHP code example of alkhatibdev / logrotation

1. Go to this page and download the library: Download alkhatibdev/logrotation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alkhatibdev / logrotation example snippets


use AlkhatibDev\LogRotation\LogRotator;

LogRotator::make()
    // Set a custom log file path (default: storage/logs/laravel.log)
    ->setLogFile(storage_path('logs/custom.log'))
    
    // Set the maximum number of months to retain logs (default: 12)
    ->setMaxMonths(12)
    
    // Set the maximum file size in KB for size-based rotation (optional) (default: null, no size-based rotation)
    ->setMaxSize(10240) // 10 MB
    
    // Enable or disable compression for archived logs (.gz) (default: true)
    ->setCompression(true)
    
    // Perform the rotation immediately
    ->rotate();

Artisan::command('logrotation:rotate', function () {
    app('logrotator')->rotate();
})->daily();

protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {
        app('logrotator')->rotate();
    })->daily();
}
bash
php artisan vendor:publish --tag=logrotation
bash
php artisan logrotation:rotate