Make -debug a global config flag, clean up logger.Debugf() callsites

This commit is contained in:
Pim van Pelt
2025-06-09 18:10:44 +02:00
parent 29d0417452
commit fb3c545e11
5 changed files with 36 additions and 28 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/posteo/go-agentx"
"govpp-snmp-example/config"
"govpp-snmp-example/ifmib"
"govpp-snmp-example/vppstats"
)
@ -20,6 +21,9 @@ func main() {
debug := flag.Bool("debug", false, "Enable debug logging")
flag.Parse()
// Set global debug flag
config.Debug = *debug
var network, address string
if strings.HasPrefix(*addr, "/") {
network = "unix"
@ -37,7 +41,7 @@ func main() {
client.ReconnectInterval = 1 * time.Second
// Create the interface MIB
interfaceMIB := ifmib.NewInterfaceMIB(*ifIndexOffset, *debug)
interfaceMIB := ifmib.NewInterfaceMIB(*ifIndexOffset)
// Register the interface MIB with the AgentX client
if err := interfaceMIB.RegisterWithClient(client); err != nil {
@ -45,7 +49,7 @@ func main() {
}
// Start VPP stats routine with callback to update MIB
vppstats.StartStatsRoutine(*vppStatsAddr, time.Duration(*period*1000)*time.Millisecond, interfaceMIB.UpdateStats, *debug)
vppstats.StartStatsRoutine(*vppStatsAddr, time.Duration(*period*1000)*time.Millisecond, interfaceMIB.UpdateStats)
for {
time.Sleep(100 * time.Millisecond)