From 48183d668db07916edb11da51e9777bcc754485b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 18 Jan 2026 12:09:57 +0000 Subject: [PATCH] Add debug logging to guard registry - Added debug logger with namespace guard:registry - Added logging to NewRegistry, Register, Get, Remove, and CreateGuard functions - Follows project logging conventions with meaningful messages - No side effects in log arguments --- internal/guard/registry.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/guard/registry.go b/internal/guard/registry.go index 888f7fb2..47a4a687 100644 --- a/internal/guard/registry.go +++ b/internal/guard/registry.go @@ -4,8 +4,12 @@ import ( "fmt" "log" "sync" + + "github.com/githubnext/gh-aw-mcpg/internal/logger" ) +var debugLog = logger.New("guard:registry") + // Registry manages guard instances for different MCP servers type Registry struct { guards map[string]Guard // serverID -> guard @@ -14,6 +18,7 @@ type Registry struct { // NewRegistry creates a new guard registry func NewRegistry() *Registry { + debugLog.Print("Creating new guard registry") return &Registry{ guards: make(map[string]Guard), } @@ -21,6 +26,7 @@ func NewRegistry() *Registry { // Register registers a guard for a specific server func (r *Registry) Register(serverID string, guard Guard) { + debugLog.Printf("Registering guard for serverID=%s, guardName=%s", serverID, guard.Name()) r.mu.Lock() defer r.mu.Unlock() @@ -30,14 +36,17 @@ func (r *Registry) Register(serverID string, guard Guard) { // Get retrieves the guard for a server, or returns a noop guard if not found func (r *Registry) Get(serverID string) Guard { + debugLog.Printf("Getting guard for serverID=%s", serverID) r.mu.RLock() defer r.mu.RUnlock() if guard, ok := r.guards[serverID]; ok { + debugLog.Printf("Found guard for serverID=%s, guardName=%s", serverID, guard.Name()) return guard } // Return noop guard as default + debugLog.Printf("No guard registered for serverID=%s, returning noop guard", serverID) log.Printf("[Guard] No guard registered for server '%s', using noop guard", serverID) return NewNoopGuard() } @@ -52,6 +61,7 @@ func (r *Registry) Has(serverID string) bool { // Remove removes a guard registration func (r *Registry) Remove(serverID string) { + debugLog.Printf("Removing guard for serverID=%s", serverID) r.mu.Lock() defer r.mu.Unlock() delete(r.guards, serverID) @@ -100,19 +110,23 @@ func RegisterGuardType(name string, factory GuardFactory) { // CreateGuard creates a guard instance by name using registered factories func CreateGuard(name string) (Guard, error) { + debugLog.Printf("Creating guard with name=%s", name) registeredGuardsMu.RLock() defer registeredGuardsMu.RUnlock() // Handle built-in guards if name == "noop" || name == "" { + debugLog.Print("Using built-in noop guard") return NewNoopGuard(), nil } // Try to find in registered factories if factory, ok := registeredGuards[name]; ok { + debugLog.Printf("Found factory for guard type: %s", name) return factory() } + debugLog.Printf("Unknown guard type: %s", name) return nil, fmt.Errorf("unknown guard type: %s", name) }