From 3511376c2c2f029b3f11d72c8f3afd4ee502b219 Mon Sep 17 00:00:00 2001 From: yangjianbo Date: Thu, 12 Feb 2026 19:07:16 +0800 Subject: [PATCH] =?UTF-8?q?chore(logging):=20=E9=BB=98=E8=AE=A4=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20console=20=E6=99=AE=E9=80=9A=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将配置默认 log.format 从 json 调整为 console\n- 将 logger 初始化兜底默认格式调整为 console\n- 同步更新 deploy 配置示例 --- backend/internal/config/config.go | 2 +- backend/internal/pkg/logger/options.go | 2 +- deploy/config.example.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/internal/config/config.go b/backend/internal/config/config.go index 3e336ab8..861351de 100644 --- a/backend/internal/config/config.go +++ b/backend/internal/config/config.go @@ -866,7 +866,7 @@ func setDefaults() { // Log viper.SetDefault("log.level", "info") - viper.SetDefault("log.format", "json") + viper.SetDefault("log.format", "console") viper.SetDefault("log.service_name", "sub2api") viper.SetDefault("log.env", "production") viper.SetDefault("log.caller", true) diff --git a/backend/internal/pkg/logger/options.go b/backend/internal/pkg/logger/options.go index c14bb41a..efcd701c 100644 --- a/backend/internal/pkg/logger/options.go +++ b/backend/internal/pkg/logger/options.go @@ -53,7 +53,7 @@ func (o InitOptions) normalized() InitOptions { } out.Format = strings.ToLower(strings.TrimSpace(out.Format)) if out.Format == "" { - out.Format = "json" + out.Format = "console" } out.ServiceName = strings.TrimSpace(out.ServiceName) if out.ServiceName == "" { diff --git a/deploy/config.example.yaml b/deploy/config.example.yaml index 2b553321..f016fd49 100644 --- a/deploy/config.example.yaml +++ b/deploy/config.example.yaml @@ -296,7 +296,7 @@ log: level: "info" # Log format: json/console # 日志格式:json/console - format: "json" + format: "console" # Service name field written into each log line # 每条日志都会附带 service 字段 service_name: "sub2api"