refactor(log): replace stdlib log with the application JSON logger
Every log.Printf/Fatalf becomes a structured slog call through internal/log: request handlers use the request-scoped logger (applog.FromContext, carrying request_id), startup failures exit via a fatal() helper that still emits JSON, and the seedsample/dumpschema CLIs bootstrap the same JSON logger. Stale client_test expectations aligned with the refactored wrapper-call logging (message casing, result attr, ERROR level). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
applog "geniusrun/backend/internal/log"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -262,7 +261,7 @@ func (s *Server) removeUserClient(userID int64) {
|
||||
|
||||
if ok {
|
||||
if err := client.Close(); err != nil {
|
||||
log.Printf("api: close garmin client for deleted user %d: %v", userID, err)
|
||||
slog.Error("close garmin client for deleted user", "user_id", userID, "error", err)
|
||||
}
|
||||
}
|
||||
if s.ClientConfig.TokenStorePath == "" {
|
||||
@@ -270,7 +269,7 @@ func (s *Server) removeUserClient(userID int64) {
|
||||
}
|
||||
tokenStoreDir := filepath.Join(s.ClientConfig.TokenStorePath, strconv.FormatInt(userID, 10))
|
||||
if err := os.RemoveAll(tokenStoreDir); err != nil {
|
||||
log.Printf("api: remove token store dir for deleted user %d: %v", userID, err)
|
||||
slog.Error("remove token store dir for deleted user", "user_id", userID, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +316,7 @@ func (s *Server) backgroundSync(userID int64, fn func(ctx context.Context) error
|
||||
s.mu.Unlock()
|
||||
}()
|
||||
if err := fn(context.Background()); err != nil {
|
||||
log.Printf("api: background sync error (user %d): %v", userID, err)
|
||||
slog.Error("background sync failed", "user_id", userID, "error", err)
|
||||
}
|
||||
}()
|
||||
return true
|
||||
@@ -337,7 +336,7 @@ func writeJSON(w http.ResponseWriter, status int, v any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
if err := json.NewEncoder(w).Encode(v); err != nil {
|
||||
log.Printf("api: encode response: %v", err)
|
||||
slog.Error("encode response", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user