Add a logger that auto-includes file+callsite
This commit is contained in:
@ -7,6 +7,8 @@ import (
|
||||
"go.fd.io/govpp/adapter/statsclient"
|
||||
"go.fd.io/govpp/api"
|
||||
"go.fd.io/govpp/core"
|
||||
|
||||
"govpp-snmp-example/logger"
|
||||
)
|
||||
|
||||
type StatsCallback func(*api.InterfaceStats)
|
||||
@ -17,9 +19,7 @@ func StartStatsRoutine(statsSocketPath string, period time.Duration, callback St
|
||||
}
|
||||
|
||||
func statsRoutine(statsSocketPath string, period time.Duration, callback StatsCallback, debug bool) {
|
||||
if debug {
|
||||
log.Printf("Starting VPP stats routine with socket: %s, period: %v", statsSocketPath, period)
|
||||
}
|
||||
logger.Debugf(debug, "Starting VPP stats routine with socket: %s, period: %v", statsSocketPath, period)
|
||||
|
||||
// Create stats client
|
||||
client := statsclient.NewStatsClient(statsSocketPath)
|
||||
@ -52,17 +52,17 @@ func queryInterfaceStats(c *core.StatsConnection, callback StatsCallback, debug
|
||||
|
||||
// Use the GetInterfaceStats method - this is the correct approach
|
||||
if err := c.GetInterfaceStats(stats); err != nil {
|
||||
log.Printf("Failed to get interface stats: %v", err)
|
||||
logger.Printf("Failed to get interface stats: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Always log basic info
|
||||
log.Printf("Retrieved stats for %d interfaces", len(stats.Interfaces))
|
||||
logger.Printf("Retrieved stats for %d interfaces", len(stats.Interfaces))
|
||||
|
||||
// Debug logging for individual interfaces
|
||||
if debug {
|
||||
for _, iface := range stats.Interfaces {
|
||||
log.Printf("Interface %d (%s): RX %d pkts/%d bytes, TX %d pkts/%d bytes",
|
||||
logger.Debugf(debug, "Interface %d (%s): RX %d pkts/%d bytes, TX %d pkts/%d bytes",
|
||||
iface.InterfaceIndex, iface.InterfaceName,
|
||||
iface.Rx.Packets, iface.Rx.Bytes,
|
||||
iface.Tx.Packets, iface.Tx.Bytes)
|
||||
|
Reference in New Issue
Block a user