#feature: update log format
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user