Add structured logging with zerolog
- Implement zerolog logger package with configurable levels - Add contextual logging middleware (request_id, user_id, method, path, status, duration) - Support both JSON (production) and human-readable (development) formats - Add LOG_LEVEL and ENVIRONMENT configuration variables - Replace standard log calls with structured logger throughout application - Integrate logger in HTTP router and auth middleware
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"apocapoc-api/internal/infrastructure/auth"
|
||||
"apocapoc-api/internal/infrastructure/logger"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
@@ -35,6 +36,7 @@ func AuthMiddleware(jwtService *auth.JWTService) func(http.Handler) http.Handler
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), UserIDKey, claims.UserID)
|
||||
ctx = logger.AddUserID(ctx, claims.UserID)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user