From 2dfdb1ad747bc49848ad564c24f3ec33dbedcaff Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Sun, 6 Mar 2022 16:42:58 +0100 Subject: [PATCH] set log-level to info, change output to only the best server name --- main.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index c2dd93a..c04397f 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,9 @@ package main import ( "encoding/json" + "fmt" "github.com/go-ping/ping" + "github.com/rs/zerolog" "github.com/rs/zerolog/log" "io" "io/ioutil" @@ -13,10 +15,11 @@ import ( var pings = make(map[string]time.Duration) func main() { - + zerolog.SetGlobalLevel(zerolog.InfoLevel) servers := getServers() bestIndex := selectBestServerIndex(servers) - log.Info().Interface("best", servers[bestIndex]).Msg("Best Latency Server found.") + log.Debug().Interface("server", servers[bestIndex]).Msg("Best latency server found.") + fmt.Println(servers[bestIndex].Hostname) } func selectBestServerIndex(servers []server) int { @@ -69,7 +72,7 @@ func serverLatency(s server) (time.Duration, error) { } var duration time.Duration pinger.OnRecv = func(pkt *ping.Packet) { - log.Info().Str("Server", s.Hostname).IPAddr("IP", pkt.IPAddr.IP).Dur("RTT", pkt.Rtt).Msg("Added server latency.") + log.Debug().Str("Server", s.Hostname).IPAddr("IP", pkt.IPAddr.IP).Dur("RTT", pkt.Rtt).Msg("Added server latency.") duration = pkt.Rtt } err = pinger.Run()