feat(log): replace standard logger with zerolog

- Integrate `rs/zerolog` for structured and leveled logging
- Add `EZ_LOG_LEVEL` environment variable support (default: info)
- Configure console output with timestamps and service fields
- Migrate `main.go` and `LogWriter` to use the new logger instance
- Update README with logging configuration and design details
This commit is contained in:
zenfun
2025-12-12 22:39:10 +08:00
parent 5826db3954
commit 5891722526
5 changed files with 64 additions and 18 deletions

View File

@@ -2,10 +2,10 @@ package service
import (
"context"
"log"
"time"
"github.com/ez-api/ez-api/internal/model"
"github.com/rs/zerolog/log"
"gorm.io/gorm"
)
@@ -47,7 +47,7 @@ func (w *LogWriter) Start(ctx context.Context) {
return
}
if err := w.db.Create(&buf).Error; err != nil {
log.Printf("log batch insert failed: %v", err)
log.Error().Err(err).Msg("log batch insert failed")
}
buf = buf[:0]
}