#feature: update log format
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class CleanScheduledTaskLogsCommand extends Command
|
||||
@@ -18,13 +19,13 @@ class CleanScheduledTaskLogsCommand extends Command
|
||||
$logPath = storage_path('logs/scheduled-tasks');
|
||||
|
||||
if (!File::exists($logPath)) {
|
||||
$this->info('日志目录不存在,无需清理');
|
||||
Log::info('日志目录不存在,无需清理');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$cutoffDate = Carbon::now()->subDays($days);
|
||||
$this->info("开始清理 {$days} 天前的定时任务日志...");
|
||||
$this->info("截止日期: {$cutoffDate->format('Y-m-d')}");
|
||||
Log::info("开始清理 {$days} 天前的定时任务日志...");
|
||||
Log::info("截止日期: {$cutoffDate->format('Y-m-d')}");
|
||||
|
||||
$files = File::files($logPath);
|
||||
$deletedCount = 0;
|
||||
@@ -44,15 +45,15 @@ class CleanScheduledTaskLogsCommand extends Command
|
||||
File::delete($file->getPathname());
|
||||
$deletedCount++;
|
||||
|
||||
$this->line("已删除: {$filename} (" . $this->formatBytes($fileSize) . ")");
|
||||
Log::info("已删除: {$filename} (" . $this->formatBytes($fileSize) . ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($deletedCount > 0) {
|
||||
$this->info("清理完成!共删除 {$deletedCount} 个日志文件,释放空间: " . $this->formatBytes($totalSize));
|
||||
Log::info("清理完成!共删除 {$deletedCount} 个日志文件,释放空间: " . $this->formatBytes($totalSize));
|
||||
} else {
|
||||
$this->info('没有需要清理的日志文件');
|
||||
Log::info('没有需要清理的日志文件');
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user