Replace all Printf logging with structured zerolog in runtime files
Migrates CHORUS logging to 100% structured JSON format with ISO 8601 timestamps for all runtime-critical subsystems. Files modified: - internal/runtime/shared.go: SimpleTaskTracker task completion logging - api/http_server.go: HTTP server, council opportunity, and status logging - pubsub/pubsub.go: PubSub initialization, topic management, and message handlers - discovery/mdns.go: mDNS peer discovery and connection logging All Printf calls replaced with structured zerolog logging using: - .Info() for informational messages - .Warn() for warnings and errors - .Debug() for verbose debug output - Structured fields: peer_id, topic_name, council_id, etc. Version bumped to 0.5.40 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,9 +5,11 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"chorus/internal/logging"
|
||||
"github.com/libp2p/go-libp2p/core/host"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
"github.com/libp2p/go-libp2p/p2p/discovery/mdns"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
// MDNSDiscovery handles mDNS peer discovery for local network
|
||||
@@ -18,6 +20,7 @@ type MDNSDiscovery struct {
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
serviceTag string
|
||||
logger zerolog.Logger
|
||||
}
|
||||
|
||||
// mdnsNotifee handles discovered peers
|
||||
@@ -25,6 +28,7 @@ type mdnsNotifee struct {
|
||||
h host.Host
|
||||
ctx context.Context
|
||||
peersChan chan peer.AddrInfo
|
||||
logger zerolog.Logger
|
||||
}
|
||||
|
||||
// NewMDNSDiscovery creates a new mDNS discovery service
|
||||
@@ -35,11 +39,14 @@ func NewMDNSDiscovery(ctx context.Context, h host.Host, serviceTag string) (*MDN
|
||||
|
||||
discoveryCtx, cancel := context.WithCancel(ctx)
|
||||
|
||||
logger := logging.ForComponent(logging.ComponentP2P)
|
||||
|
||||
// Create notifee to handle discovered peers
|
||||
notifee := &mdnsNotifee{
|
||||
h: h,
|
||||
ctx: discoveryCtx,
|
||||
peersChan: make(chan peer.AddrInfo, 10),
|
||||
logger: logger,
|
||||
}
|
||||
|
||||
// Create mDNS service
|
||||
@@ -52,6 +59,7 @@ func NewMDNSDiscovery(ctx context.Context, h host.Host, serviceTag string) (*MDN
|
||||
ctx: discoveryCtx,
|
||||
cancel: cancel,
|
||||
serviceTag: serviceTag,
|
||||
logger: logger,
|
||||
}
|
||||
|
||||
// Start the service
|
||||
@@ -63,7 +71,7 @@ func NewMDNSDiscovery(ctx context.Context, h host.Host, serviceTag string) (*MDN
|
||||
// Start background peer connection handler
|
||||
go discovery.handleDiscoveredPeers()
|
||||
|
||||
fmt.Printf("🔍 mDNS Discovery started with service tag: %s\n", serviceTag)
|
||||
logger.Info().Str("service_tag", serviceTag).Msg("mDNS Discovery started")
|
||||
return discovery, nil
|
||||
}
|
||||
|
||||
@@ -90,13 +98,13 @@ func (d *MDNSDiscovery) handleDiscoveredPeers() {
|
||||
}
|
||||
|
||||
// Attempt to connect
|
||||
fmt.Printf("🤝 Discovered peer %s, attempting connection...\n", peerInfo.ID.ShortString())
|
||||
|
||||
d.logger.Info().Str("peer_id", peerInfo.ID.ShortString()).Msg("Discovered peer, attempting connection")
|
||||
|
||||
connectCtx, cancel := context.WithTimeout(d.ctx, 10*time.Second)
|
||||
if err := d.host.Connect(connectCtx, peerInfo); err != nil {
|
||||
fmt.Printf("❌ Failed to connect to peer %s: %v\n", peerInfo.ID.ShortString(), err)
|
||||
d.logger.Warn().Err(err).Str("peer_id", peerInfo.ID.ShortString()).Msg("Failed to connect to peer")
|
||||
} else {
|
||||
fmt.Printf("✅ Successfully connected to peer %s\n", peerInfo.ID.ShortString())
|
||||
d.logger.Info().Str("peer_id", peerInfo.ID.ShortString()).Msg("Successfully connected to peer")
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
@@ -119,6 +127,6 @@ func (n *mdnsNotifee) HandlePeerFound(pi peer.AddrInfo) {
|
||||
// Peer info sent to channel
|
||||
default:
|
||||
// Channel is full, skip this peer
|
||||
fmt.Printf("⚠️ Discovery channel full, skipping peer %s\n", pi.ID.ShortString())
|
||||
n.logger.Warn().Str("peer_id", pi.ID.ShortString()).Msg("Discovery channel full, skipping peer")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user