fix(logger): remove init() function that was overriding config level

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 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-06 03:07:30 -08:00
parent 32e3970f34
commit ac1858a19e
1 changed files with 15 additions and 11 deletions

View File

@ -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()
// }
// }