diff --git a/internal/server/server.go b/internal/server/server.go index a4ee0f2..708c044 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -3,15 +3,16 @@ package server import ( "context" "fmt" - "log" "net/http" "strings" "sync/atomic" "github.com/gin-gonic/gin" + "github.com/rs/zerolog/log" "github.com/fujin/anthropic-proxy/internal/auth" "github.com/fujin/anthropic-proxy/internal/config" + "github.com/fujin/anthropic-proxy/internal/logging" "github.com/fujin/anthropic-proxy/internal/proxy" ) @@ -37,6 +38,7 @@ func New(cfg *config.Config, pool *auth.Pool, profile *proxy.SniffedProfile) *Se engine.Use(gin.Recovery()) engine.Use(corsMiddleware()) engine.Use(s.authMiddleware()) + engine.Use(logging.GinRequestLogger()) handler := proxy.HandleMessages(pool, profile, func() *proxy.Sanitizer { return s.sanitizer.Load() @@ -50,7 +52,7 @@ func New(cfg *config.Config, pool *auth.Pool, profile *proxy.SniffedProfile) *Se c.JSON(http.StatusOK, gin.H{"status": "ok"}) }) engine.NoRoute(func(c *gin.Context) { - log.Printf("unmatched route: %s %s", c.Request.Method, c.Request.URL.Path) + log.Warn().Str("method", c.Request.Method).Str("path", c.Request.URL.Path).Msg("unmatched route") c.JSON(http.StatusNotFound, gin.H{"error": "not found"}) }) @@ -85,8 +87,7 @@ func (s *Server) handleReload() gin.HandlerFunc { keys := makeKeySet(cfg.APIKeys) s.apiKeys.Store(&keys) - log.Printf("config reloaded: %d tool renames, %d system rules, %d body rules, %d api keys", - len(cfg.Sanitize.Tools), len(cfg.Sanitize.System), len(cfg.Sanitize.Body), len(cfg.APIKeys)) + log.Info().Int("tool_renames", len(cfg.Sanitize.Tools)).Int("system_rules", len(cfg.Sanitize.System)).Int("body_rules", len(cfg.Sanitize.Body)).Int("api_keys", len(cfg.APIKeys)).Msg("config reloaded") c.JSON(http.StatusOK, gin.H{ "status": "reloaded",