PHP code example of parvion / laravel-log-pruner
1. Go to this page and download the library: Download parvion/laravel-log-pruner 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/ */
parvion / laravel-log-pruner example snippets
return [
// ── Master on/off switch ──────────────────────────────────────────────
'enabled' => env('LOG_PRUNER_ENABLED', true),
// ── Retention period (days) ───────────────────────────────────────────
'days' => env('LOG_PRUNER_DAYS', 15),
// ── Enable / disable each phase independently ─────────────────────────
'features' => [
'log_rotation' => env('LOG_PRUNER_FEATURE_ROTATION', true),
'backup_pruning' => env('LOG_PRUNER_FEATURE_BACKUP_PRUNING', true),
'queue_restart' => env('LOG_PRUNER_FEATURE_QUEUE_RESTART', true),
'db_pruning' => env('LOG_PRUNER_FEATURE_DB_PRUNING', true),
'email_report' => env('LOG_PRUNER_FEATURE_EMAIL', true),
],
// ── Tables to DELETE old rows from (with custom retention) ────────────
'tables' => [
'system_logs' => 10, // Keeps system logs for 10 days
'audit_logs', // Keeps audit logs for global retention (15 days)
],
// ── Backup file display settings ──────────────────────────────────────
'backup' => [
'show_info' => env('LOG_PRUNER_BACKUP_SHOW_INFO', true),
'show_info_in_email' => env('LOG_PRUNER_BACKUP_SHOW_INFO_EMAIL', true),
'date_format' => env('LOG_PRUNER_BACKUP_DATE_FORMAT', 'Y-m-d H:i'),
],
// ── Email report settings ─────────────────────────────────────────────
'mail' => [
'enabled' => env('LOG_PRUNER_MAIL_ENABLED', true),
'recipients' => array_filter(array_map('trim',
explode(',', env('LOG_PRUNER_MAIL_RECIPIENTS', '')))),
'subject_prefix' => env('LOG_PRUNER_MAIL_SUBJECT_PREFIX', '[Log Pruner]'),
],
];
use Illuminate\Support\Facades\Schedule;
// All settings come from config/log-pruner.php automatically.
// Pass CLI options here only if you need to override config for this schedule.
Schedule::command('logs:rotate-and-prune')
->dailyAt('02:00')
->timezone('Asia/Kolkata')
->withoutOverlapping()
->runInBackground();
Schedule::command('logs:rotate-and-prune', [
'--days' => 15,
'--tables' => 'system_logs,audit_logs',
'--email' => '[email protected] ',
])
->dailyAt('02:00')
->timezone('Asia/Kolkata')
->withoutOverlapping()
->runInBackground();
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected function schedule(Schedule $schedule): void
{
$schedule->command('logs:rotate-and-prune')
->dailyAt('02:00')
->timezone('Asia/Kolkata')
->withoutOverlapping()
->runInBackground();
}
}
bash
php artisan vendor:publish --tag=log-pruner-config
bash
php artisan logs:rotate-and-prune
bash
php artisan logs:rotate-and-prune