tighten up logging

This commit is contained in:
Pim van Pelt
2025-06-24 07:51:37 +02:00
parent 3401c96112
commit 8ed14834f5
4 changed files with 13 additions and 9 deletions

View File

@ -184,7 +184,7 @@ func (m *InterfaceMIB) UpdateStats(interfaceStats *api.InterfaceStats) {
} }
if m.ifXTableSession != nil { if m.ifXTableSession != nil {
m.ifXTableSession.Handler = m.handler m.ifXTableSession.Handler = m.handler
logger.Printf("Updated session handlers with new IF-MIB data") logger.Printf("Updated session handlers with new IF-MIB data for %d interfaces", len(m.stats))
} }
logger.Debugf("IF-MIB now contains %d interfaces", len(m.stats)) logger.Debugf("IF-MIB now contains %d interfaces", len(m.stats))

View File

@ -105,14 +105,14 @@ func (im *InterfaceManager) eventMonitoringRoutine() {
if im.client.IsConnected() { if im.client.IsConnected() {
if !im.watchingEvents { if !im.watchingEvents {
if err := im.InitializeEventWatching(); err != nil { if err := im.InitializeEventWatching(); err != nil {
logger.Debugf("Failed to initialize interface event watching: %v", err) logger.Printf("Failed to initialize interface event watching: %v", err)
} else { } else {
logger.Debugf("Interface event watching restarted after reconnection") logger.Printf("Interface event watching started")
} }
} }
} else { } else {
if im.watchingEvents { if im.watchingEvents {
logger.Debugf("VPP connection lost, interface event watching will restart on reconnection") logger.Printf("VPP connection lost, interface event watching will restart on reconnection")
im.watchingEvents = false im.watchingEvents = false
} }
} }
@ -264,7 +264,7 @@ func watchInterfaceEvents(ch api.Channel, callback func()) error {
logger.Debugf("Interface event listener waiting for events...") logger.Debugf("Interface event listener waiting for events...")
for notif := range notifChan { for notif := range notifChan {
e := notif.(*interfaces.SwInterfaceEvent) e := notif.(*interfaces.SwInterfaceEvent)
logger.Debugf("interface event: SwIfIndex=%d, Flags=%d, Deleted=%t", logger.Printf("interface event: SwIfIndex=%d, Flags=%d, Deleted=%t",
e.SwIfIndex, e.Flags, e.Deleted) e.SwIfIndex, e.Flags, e.Deleted)
// When an interface event occurs, call the callback // When an interface event occurs, call the callback

View File

@ -32,6 +32,10 @@ func TestNewInterfaceManager(t *testing.T) {
if manager.watchingEvents { if manager.watchingEvents {
t.Error("InterfaceManager should not be watching events initially") t.Error("InterfaceManager should not be watching events initially")
} }
if manager.hasConnectedBefore {
t.Error("InterfaceManager should not have hasConnectedBefore set initially")
}
} }
func TestInterfaceManagerSetEventCallback(t *testing.T) { func TestInterfaceManagerSetEventCallback(t *testing.T) {

View File

@ -95,11 +95,11 @@ func (sm *StatsManager) statsRoutine() {
logger.Printf("VPP connection lost, attempting reconnect...") logger.Printf("VPP connection lost, attempting reconnect...")
wasConnected = false wasConnected = false
} else { } else {
logger.Debugf("VPP not connected, attempting connection...") logger.Printf("VPP not connected, attempting connection...")
} }
if err := sm.client.Connect(); err != nil { if err := sm.client.Connect(); err != nil {
logger.Debugf("Failed to connect to VPP: %v", err) logger.Printf("Failed to connect to VPP: %v", err)
time.Sleep(time.Second) time.Sleep(time.Second)
continue continue
} }
@ -139,8 +139,8 @@ func (sm *StatsManager) queryAndReportStats() bool {
return false return false
} }
// Always log basic info // Debug log basic info
logger.Printf("Retrieved stats for %d interfaces", len(stats.Interfaces)) logger.Debugf("Retrieved stats for %d interfaces", len(stats.Interfaces))
// Debug logging for individual interfaces // Debug logging for individual interfaces
for _, iface := range stats.Interfaces { for _, iface := range stats.Interfaces {