From ac1858a19e192d81f64a3d6beeb9bcb88a9266ab Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 6 Dec 2025 03:07:30 -0800 Subject: [PATCH] fix(logger): remove init() function that was overriding config level MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Logger was always using info level despite MPC_LOGGER_LEVEL=debug Root cause: The init() function in logger.go was calling InitProduction() which created a zap.NewProduction() logger with hardcoded info level. This happened before main() called logger.Init(cfg), so the config was being ignored. Solution: 1. Removed init() function to prevent early logger initialization 2. Added zap.ReplaceGlobals() in Init() to ensure config takes effect 3. Removed unused "os" import References: - https://pkg.go.dev/go.uber.org/zap - https://stackoverflow.com/questions/57745017/ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- backend/mpc-system/pkg/logger/logger.go | 26 ++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/backend/mpc-system/pkg/logger/logger.go b/backend/mpc-system/pkg/logger/logger.go index cbcb8402..eea1adee 100644 --- a/backend/mpc-system/pkg/logger/logger.go +++ b/backend/mpc-system/pkg/logger/logger.go @@ -1,8 +1,6 @@ package logger import ( - "os" - "go.uber.org/zap" "go.uber.org/zap/zapcore" ) @@ -70,6 +68,10 @@ func Init(cfg *Config) error { } Sugar = Log.Sugar() + + // Replace global zap logger to ensure our config takes effect + zap.ReplaceGlobals(Log) + return nil } @@ -158,12 +160,14 @@ func Err(err error) zap.Field { return zap.Error(err) } -func init() { - // Initialize with development logger by default - // This will be overridden when Init() is called with proper config - if os.Getenv("ENV") == "production" { - _ = InitProduction() - } else { - _ = InitDevelopment() - } -} +// Removed init() function to prevent it from overriding logger config. +// The logger will be initialized when Init() is explicitly called with config. +// func init() { +// // Initialize with development logger by default +// // This will be overridden when Init() is called with proper config +// if os.Getenv("ENV") == "production" { +// _ = InitProduction() +// } else { +// _ = InitDevelopment() +// } +// }