#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;
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\Services\GitMonitorService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class GitMonitorCacheCommand extends Command
|
||||
{
|
||||
@@ -16,11 +17,11 @@ class GitMonitorCacheCommand extends Command
|
||||
$cache = $monitor->refreshReleaseCache(true);
|
||||
|
||||
if (empty($cache)) {
|
||||
$this->warn('未获取到任何 release 版本信息,请检查配置。');
|
||||
Log::warning('未获取到任何 release 版本信息,请检查配置。');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->info(sprintf(
|
||||
Log::info(sprintf(
|
||||
'已缓存 %d 个仓库的 release 分支信息。',
|
||||
count($cache['repositories'] ?? [])
|
||||
));
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\Services\GitMonitorService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class GitMonitorCheckCommand extends Command
|
||||
{
|
||||
@@ -24,11 +25,11 @@ class GitMonitorCheckCommand extends Command
|
||||
|
||||
foreach ($results as $repo => $result) {
|
||||
if (isset($result['error'])) {
|
||||
$this->error(sprintf('[%s] %s', $repo, $result['error']));
|
||||
Log::error(sprintf('[%s] %s', $repo, $result['error']));
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->line(sprintf(
|
||||
Log::info(sprintf(
|
||||
'[%s] 分支 %s 已对齐 %s,扫描 %d 个提交。',
|
||||
$repo,
|
||||
$result['branch'],
|
||||
@@ -37,9 +38,9 @@ class GitMonitorCheckCommand extends Command
|
||||
));
|
||||
|
||||
if (!empty($result['issues']['develop_merges'])) {
|
||||
$this->warn(sprintf(' - 检测到 %d 个 develop merge:', count($result['issues']['develop_merges'])));
|
||||
Log::warning(sprintf(' - 检测到 %d 个 develop merge:', count($result['issues']['develop_merges'])));
|
||||
foreach ($result['issues']['develop_merges'] as $commit) {
|
||||
$this->warn(sprintf(
|
||||
Log::warning(sprintf(
|
||||
' • %s %s (%s)',
|
||||
substr($commit['hash'], 0, 8),
|
||||
$commit['subject'],
|
||||
@@ -49,9 +50,9 @@ class GitMonitorCheckCommand extends Command
|
||||
}
|
||||
|
||||
if (!empty($result['issues']['missing_functions'])) {
|
||||
$this->warn(sprintf(' - 检测到 %d 个疑似缺失函数的提交:', count($result['issues']['missing_functions'])));
|
||||
Log::warning(sprintf(' - 检测到 %d 个疑似缺失函数的提交:', count($result['issues']['missing_functions'])));
|
||||
foreach ($result['issues']['missing_functions'] as $issue) {
|
||||
$this->warn(sprintf(
|
||||
Log::warning(sprintf(
|
||||
' • %s %s (%s)',
|
||||
substr($issue['commit']['hash'], 0, 8),
|
||||
$issue['commit']['subject'],
|
||||
@@ -59,7 +60,7 @@ class GitMonitorCheckCommand extends Command
|
||||
));
|
||||
foreach ($issue['details'] as $detail) {
|
||||
$functions = implode(', ', array_slice($detail['functions'], 0, 5));
|
||||
$this->warn(sprintf(' %s => %s', $detail['file'], $functions));
|
||||
Log::warning(sprintf(' %s => %s', $detail['file'], $functions));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\Services\JenkinsMonitorService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class JenkinsMonitorCommand extends Command
|
||||
{
|
||||
@@ -13,29 +14,29 @@ class JenkinsMonitorCommand extends Command
|
||||
|
||||
public function handle(JenkinsMonitorService $service): void
|
||||
{
|
||||
$this->info('开始检查 Jenkins 构建...');
|
||||
Log::info('开始检查 Jenkins 构建...');
|
||||
|
||||
$results = $service->checkAllProjects();
|
||||
|
||||
if (isset($results['skipped'])) {
|
||||
$this->warn('跳过检查: ' . ($results['reason'] ?? 'unknown'));
|
||||
Log::warning('跳过检查: ' . ($results['reason'] ?? 'unknown'));
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($results as $slug => $result) {
|
||||
if (isset($result['skipped'])) {
|
||||
$this->line(sprintf('[%s] 跳过: %s', $slug, $result['reason'] ?? 'unknown'));
|
||||
Log::info(sprintf('[%s] 跳过: %s', $slug, $result['reason'] ?? 'unknown'));
|
||||
continue;
|
||||
}
|
||||
|
||||
$newBuilds = $result['new_builds'] ?? [];
|
||||
if (empty($newBuilds)) {
|
||||
$this->line(sprintf('[%s] 无新构建', $slug));
|
||||
Log::info(sprintf('[%s] 无新构建', $slug));
|
||||
} else {
|
||||
$this->info(sprintf('[%s] 发现 %d 个新构建: #%s', $slug, count($newBuilds), implode(', #', $newBuilds)));
|
||||
Log::info(sprintf('[%s] 发现 %d 个新构建: #%s', $slug, count($newBuilds), implode(', #', $newBuilds)));
|
||||
}
|
||||
}
|
||||
|
||||
$this->info('检查完成');
|
||||
Log::info('检查完成');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Services\SlsService;
|
||||
use App\Services\AiService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LogAnalysisCommand extends Command
|
||||
{
|
||||
@@ -29,12 +30,12 @@ class LogAnalysisCommand extends Command
|
||||
): int {
|
||||
// 检查配置
|
||||
if (!$slsService->isConfigured()) {
|
||||
$this->error('SLS 服务未配置,请检查 .env 中的 SLS_* 配置项');
|
||||
Log::error('SLS 服务未配置,请检查 .env 中的 SLS_* 配置项');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
if (!$aiService->isConfigured()) {
|
||||
$this->error('AI 服务未配置,请在页面上配置 AI 提供商或设置 .env 中的 AI_* 配置项');
|
||||
Log::error('AI 服务未配置,请在页面上配置 AI 提供商或设置 .env 中的 AI_* 配置项');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ class LogAnalysisCommand extends Command
|
||||
$to = $this->parseTime($this->option('to') ?? 'now');
|
||||
|
||||
if ($from >= $to) {
|
||||
$this->error('开始时间必须早于结束时间');
|
||||
Log::error('开始时间必须早于结束时间');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
@@ -55,10 +56,10 @@ class LogAnalysisCommand extends Command
|
||||
|
||||
$query = $this->option('query');
|
||||
|
||||
$this->info("开始分析日志...");
|
||||
$this->line(" 时间范围: {$from->format('Y-m-d H:i:s')} ~ {$to->format('Y-m-d H:i:s')}");
|
||||
$this->line(" 查询语句: " . ($query ?: '*'));
|
||||
$this->line(" 分析模式: {$mode->label()}");
|
||||
Log::info("开始分析日志...");
|
||||
Log::info(" 时间范围: {$from->format('Y-m-d H:i:s')} ~ {$to->format('Y-m-d H:i:s')}");
|
||||
Log::info(" 查询语句: " . ($query ?: '*'));
|
||||
Log::info(" 分析模式: {$mode->label()}");
|
||||
$this->newLine();
|
||||
|
||||
try {
|
||||
@@ -74,17 +75,17 @@ class LogAnalysisCommand extends Command
|
||||
if ($outputPath = $this->option('output')) {
|
||||
$json = json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
file_put_contents($outputPath, $json);
|
||||
$this->info("报告已保存到: {$outputPath}");
|
||||
Log::info("报告已保存到: {$outputPath}");
|
||||
}
|
||||
|
||||
// 推送到钉钉
|
||||
if ($this->option('push')) {
|
||||
$this->line("正在推送到钉钉...");
|
||||
Log::info("正在推送到钉钉...");
|
||||
$pushed = $analysisService->pushToNotification($result);
|
||||
if ($pushed) {
|
||||
$this->info("已推送到钉钉");
|
||||
Log::info("已推送到钉钉");
|
||||
} else {
|
||||
$this->warn("钉钉推送失败");
|
||||
Log::warning("钉钉推送失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +94,7 @@ class LogAnalysisCommand extends Command
|
||||
|
||||
return Command::SUCCESS;
|
||||
} catch (\Exception $e) {
|
||||
$this->error("分析失败: {$e->getMessage()}");
|
||||
Log::error("分析失败: {$e->getMessage()}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\Services\ScheduledTaskService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ScheduledTaskRefreshCommand extends Command
|
||||
{
|
||||
@@ -14,26 +15,26 @@ class ScheduledTaskRefreshCommand extends Command
|
||||
public function handle(ScheduledTaskService $taskService): int
|
||||
{
|
||||
try {
|
||||
$this->info('开始刷新定时任务列表...');
|
||||
Log::info('开始刷新定时任务列表...');
|
||||
|
||||
$tasks = $taskService->getAllTasks();
|
||||
|
||||
$this->info(sprintf('成功刷新 %d 个定时任务', count($tasks)));
|
||||
Log::info(sprintf('成功刷新 %d 个定时任务', count($tasks)));
|
||||
|
||||
// 显示任务列表
|
||||
$this->table(
|
||||
['任务名称', '描述', '执行频率', '状态'],
|
||||
array_map(fn($task) => [
|
||||
// 记录任务列表到日志
|
||||
foreach ($tasks as $task) {
|
||||
Log::info(sprintf(
|
||||
' - %s: %s (%s) [%s]',
|
||||
$task['name'],
|
||||
$task['description'],
|
||||
$task['frequency'],
|
||||
$task['enabled'] ? '已启用' : '已禁用',
|
||||
], $tasks)
|
||||
);
|
||||
$task['enabled'] ? '已启用' : '已禁用'
|
||||
));
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
} catch (\Exception $e) {
|
||||
$this->error("刷新失败: {$e->getMessage()}");
|
||||
Log::error("刷新失败: {$e->getMessage()}");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user