From 980fc9608ffc1489774ec9f37365f7bc4db1d803 Mon Sep 17 00:00:00 2001 From: shaw Date: Tue, 24 Feb 2026 11:31:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E8=BE=93=E5=87=BA=E5=8F=8A=E6=B8=85=E7=90=86?= =?UTF-8?q?=E5=86=97=E4=BD=99=E8=BF=81=E7=A7=BB=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - logger: sinkCore 包装 tee core 时绕过了子 core 的 Check 级别过滤, 导致每条日志同时写入 stdout 和 stderr,表现为启动日志重复显示。 修复为正确委托 Check 给内部 tee core,sinkCore.Write 仅负责 sink 转发。 - migration 054: 移除冗余的遗留列回填逻辑,migration 009 已完成数据迁移, 直接删除遗留列即可。 --- backend/internal/pkg/logger/logger.go | 13 ++++---- .../054_drop_legacy_cache_columns.sql | 32 +------------------ 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/backend/internal/pkg/logger/logger.go b/backend/internal/pkg/logger/logger.go index 5cc50696..80d92517 100644 --- a/backend/internal/pkg/logger/logger.go +++ b/backend/internal/pkg/logger/logger.go @@ -351,17 +351,18 @@ func (s *sinkCore) With(fields []zapcore.Field) zapcore.Core { } func (s *sinkCore) Check(entry zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry { - if s.Enabled(entry.Level) { - return ce.AddCore(entry, s) + // Delegate to inner core (tee) so each sub-core's level enabler is respected. + // Then add ourselves for sink forwarding only. + ce = s.core.Check(entry, ce) + if ce != nil { + ce = ce.AddCore(entry, s) } return ce } func (s *sinkCore) Write(entry zapcore.Entry, fields []zapcore.Field) error { - if err := s.core.Write(entry, fields); err != nil { - return err - } - + // Only handle sink forwarding — the inner cores write via their own + // Write methods (added to CheckedEntry by s.core.Check above). mu.RLock() sink := currentSink mu.RUnlock() diff --git a/backend/migrations/054_drop_legacy_cache_columns.sql b/backend/migrations/054_drop_legacy_cache_columns.sql index 040828c2..ac73cd28 100644 --- a/backend/migrations/054_drop_legacy_cache_columns.sql +++ b/backend/migrations/054_drop_legacy_cache_columns.sql @@ -8,37 +8,7 @@ -- cache_creation_1h_tokens (defined in 001_init.sql) -- -- Migration 009 already copied data from legacy → canonical columns. --- But upgraded instances may still have post-009 writes in legacy columns. --- Backfill once more before dropping to prevent data loss. - -DO $$ -BEGIN - IF EXISTS ( - SELECT 1 - FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'usage_logs' - AND column_name = 'cache_creation5m_tokens' - ) THEN - UPDATE usage_logs - SET cache_creation_5m_tokens = cache_creation5m_tokens - WHERE cache_creation_5m_tokens = 0 - AND cache_creation5m_tokens <> 0; - END IF; - - IF EXISTS ( - SELECT 1 - FROM information_schema.columns - WHERE table_schema = 'public' - AND table_name = 'usage_logs' - AND column_name = 'cache_creation1h_tokens' - ) THEN - UPDATE usage_logs - SET cache_creation_1h_tokens = cache_creation1h_tokens - WHERE cache_creation_1h_tokens = 0 - AND cache_creation1h_tokens <> 0; - END IF; -END $$; +-- This migration drops the legacy columns to avoid confusion. ALTER TABLE usage_logs DROP COLUMN IF EXISTS cache_creation5m_tokens; ALTER TABLE usage_logs DROP COLUMN IF EXISTS cache_creation1h_tokens;