From e5ab418cad1824d252e983eb7e2f251220c81bf4 Mon Sep 17 00:00:00 2001 From: Dominik Hebeler <dominik@suma-ev.de> Date: Wed, 3 Aug 2022 13:10:12 +0200 Subject: [PATCH] truncating logs --- metager/app/Console/Commands/TruncateLogs.php | 48 +++++++++++++++++++ metager/app/Console/Kernel.php | 1 + 2 files changed, 49 insertions(+) create mode 100644 metager/app/Console/Commands/TruncateLogs.php diff --git a/metager/app/Console/Commands/TruncateLogs.php b/metager/app/Console/Commands/TruncateLogs.php new file mode 100644 index 000000000..6be63a97a --- /dev/null +++ b/metager/app/Console/Commands/TruncateLogs.php @@ -0,0 +1,48 @@ +<?php + +namespace App\Console\Commands; + +use Illuminate\Console\Command; + +class TruncateLogs extends Command +{ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'logs:truncate'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Truncates Logs that should only be kept for a day'; + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + $log_files = [ + \storage_path("logs/metager/bv_fail.csv"), + \storage_path("logs/metager/captcha_show.csv"), + \storage_path("logs/metager/captcha_solve.csv"), + ]; + foreach ($log_files as $log_file) { + if (\file_exists($log_file) && \is_writable($log_file)) { + $fp = fopen($log_file, "r+"); + try { + ftruncate($fp, 0); + } finally { + fclose($fp); + } + } + } + + return 0; + } +} diff --git a/metager/app/Console/Kernel.php b/metager/app/Console/Kernel.php index 3886053b2..d5f865445 100644 --- a/metager/app/Console/Kernel.php +++ b/metager/app/Console/Kernel.php @@ -20,6 +20,7 @@ class Kernel extends ConsoleKernel $schedule->command('requests:gather')->everyFifteenMinutes(); $schedule->command('requests:useragents')->everyFiveMinutes(); $schedule->command('logs:gather')->everyMinute(); + $schedule->command('logs:truncate')->daily()->onOneServer(); $schedule->command('spam:load')->everyMinute(); $schedule->command('load:affiliate-blacklist')->everyMinute(); $schedule->command('affilliates:store')->everyMinute() -- GitLab