refactor: migrate from zerolog to zap logging library

Replace github.com/rs/zerolog with go.uber.org/zap throughout the codebase
to improve performance and provide better structured logging capabilities.

Key changes:
- Replace zerolog imports with zap and zapcore
- Implement custom Logger wrapper in log.go to maintain zerolog-like API
- Add LogEvent struct with chained methods (Str, Int, Err, Bool, etc.)
- Update all logging calls to use the new zap-based wrapper
- Replace JSON encoders with Console encoders for better readability

Benefits:
- Better performance with zap's optimized logging
- Consistent structured logging across all components
- Maintained zerolog-like API for easy migration
- Proper field context preservation for debugging
- Multi-core logging architecture for better output control

All tests pass and build succeeds.
This commit is contained in:
Cuong Manh Le
2025-07-21 19:50:43 +07:00
committed by Cuong Manh Le
parent 016c566307
commit d41334c66f
15 changed files with 400 additions and 135 deletions
+8 -6
View File
@@ -5,8 +5,8 @@ import (
"time"
"github.com/Masterminds/semver/v3"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"github.com/Control-D-Inc/ctrld"
)
@@ -173,10 +173,10 @@ func Test_shouldUpgrade(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {
// Create test logger
testLogger := zerolog.New(zerolog.NewTestWriter(t)).With().Logger()
testLogger := &ctrld.Logger{Logger: zap.NewNop()}
// Call the function and capture the result
result := shouldUpgrade(tc.versionTarget, tc.currentVersion, &testLogger)
result := shouldUpgrade(tc.versionTarget, tc.currentVersion, testLogger)
// Assert the expected result
assert.Equal(t, tc.shouldUpgrade, result, tc.description)
@@ -221,10 +221,10 @@ func Test_selfUpgradeCheck(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {
// Create test logger
testLogger := zerolog.New(zerolog.NewTestWriter(t)).With().Logger()
testLogger := &ctrld.Logger{Logger: zap.NewNop()}
// Call the function and capture the result
result := selfUpgradeCheck(tc.versionTarget, tc.currentVersion, &testLogger)
result := selfUpgradeCheck(tc.versionTarget, tc.currentVersion, testLogger)
// Assert the expected result
assert.Equal(t, tc.shouldUpgrade, result, tc.description)
@@ -256,8 +256,10 @@ func Test_performUpgrade(t *testing.T) {
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
// Create test logger
testLogger := &ctrld.Logger{Logger: zap.NewNop()}
// Call the function and capture the result
result := performUpgrade(tc.versionTarget)
result := performUpgrade(tc.versionTarget, testLogger)
assert.Equal(t, tc.expectedResult, result, tc.description)
})
}