mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
refactor(log): migrate from zerolog to structured slog with bridge
- Replace direct zerolog usage with standard library `log/slog` in business code - Add `internal/logging` package with zerolog bridge handler for structured output - Create `internal/jsoncodec` package to centralize JSON encoding/decoding using Sonic - Update all services and main entry point to use new logging interface - Maintain backward compatibility with existing zerolog console output - Remove custom logger setup in favor of structured logging bridge
This commit is contained in:
@@ -2,10 +2,10 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"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.Error().Err(err).Msg("log batch insert failed")
|
||||
slog.Default().Error("log batch insert failed", "err", err)
|
||||
}
|
||||
buf = buf[:0]
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/ez-api/ez-api/internal/jsoncodec"
|
||||
"github.com/ez-api/ez-api/internal/model"
|
||||
"github.com/ez-api/ez-api/internal/util"
|
||||
"github.com/redis/go-redis/v9"
|
||||
@@ -212,7 +212,7 @@ func (s *SyncService) SyncAll(db *gorm.DB) error {
|
||||
if p.BanUntil != nil {
|
||||
snap.BanUntil = p.BanUntil.UTC().Unix()
|
||||
}
|
||||
payload, err := sonic.Marshal(snap)
|
||||
payload, err := jsoncodec.Marshal(snap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal provider %d: %w", p.ID, err)
|
||||
}
|
||||
@@ -271,7 +271,7 @@ func (s *SyncService) SyncAll(db *gorm.DB) error {
|
||||
SupportsFIM: m.SupportsFIM,
|
||||
MaxOutputTokens: m.MaxOutputTokens,
|
||||
}
|
||||
payload, err := sonic.Marshal(snap)
|
||||
payload, err := jsoncodec.Marshal(snap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal model %s: %w", m.Name, err)
|
||||
}
|
||||
@@ -286,7 +286,7 @@ func (s *SyncService) SyncAll(db *gorm.DB) error {
|
||||
}
|
||||
|
||||
func (s *SyncService) hsetJSON(ctx context.Context, key, field string, val interface{}) error {
|
||||
payload, err := sonic.Marshal(val)
|
||||
payload, err := jsoncodec.Marshal(val)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal %s:%s: %w", key, field, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user