mirror of
https://github.com/Deathgarden-Rebirth/Deathgarden_Rebirth-Rewrite.git
synced 2026-04-26 02:00:32 -05:00
Merge pull request #55 from Deathgarden-Rebirth/log-cleanup
New Command: Log file clean up
This commit is contained in:
commit
8c68572494
65
dist/app/Console/Commands/CleanupLogs.php
vendored
Normal file
65
dist/app/Console/Commands/CleanupLogs.php
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DirectoryIterator;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Str;
|
||||
|
||||
class CleanupLogs extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:cleanup-logs';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Cleanup old log files.';
|
||||
|
||||
// Delete files older than this number of days.
|
||||
const FILE_DAYS_OLD = 14;
|
||||
|
||||
// Delete session files older than this number of days.
|
||||
const SESSION_FILE_DAYS_OLD = 7;
|
||||
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$disk = Storage::disk('logs');
|
||||
$files = $disk->allFiles();
|
||||
$now = Carbon::now();
|
||||
|
||||
// Delete older modified files
|
||||
foreach ($files as $file) {
|
||||
$lastModified = Carbon::createFromTimestamp($disk->lastModified($file));
|
||||
|
||||
if(Str::startsWith($file, 'sessions/'))
|
||||
$shouldDelete = $now->diff($lastModified)->total('days') * -1 > self::SESSION_FILE_DAYS_OLD;
|
||||
else
|
||||
$shouldDelete = $now->diff($lastModified)->total('days') * -1 > self::FILE_DAYS_OLD;
|
||||
|
||||
if($shouldDelete)
|
||||
$disk->delete($file);
|
||||
}
|
||||
|
||||
//Loop over all directories to delete empty ones.
|
||||
$directories = $disk->allDirectories();
|
||||
foreach ($directories as $directory) {
|
||||
$files = $disk->allFiles($directory);
|
||||
|
||||
if(count($files) === 0)
|
||||
$disk->deleteDirectory($directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
dist/app/Console/Kernel.php
vendored
1
dist/app/Console/Kernel.php
vendored
|
|
@ -16,6 +16,7 @@ protected function schedule(Schedule $schedule): void
|
|||
$schedule->command('matchmaking:process')->everyTwentySeconds();
|
||||
$schedule->command('matchmaking:cleanup')->everyThirtySeconds();
|
||||
$schedule->command('app:generate-timed-challenges')->daily();
|
||||
$schedule->command('app:cleanup-logs')->daily();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
6
dist/config/filesystems.php
vendored
6
dist/config/filesystems.php
vendored
|
|
@ -44,6 +44,12 @@
|
|||
'throw' => false,
|
||||
],
|
||||
|
||||
'logs' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('logs'),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
'patches' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/patches'),
|
||||
|
|
|
|||
2
dist/config/logging.php
vendored
2
dist/config/logging.php
vendored
|
|
@ -59,7 +59,7 @@
|
|||
],
|
||||
|
||||
'single' => [
|
||||
'driver' => 'single',
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user