From 02c3a7514c0475adb7c53014cef9b48f294ced8d Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Mon, 3 Jan 2022 19:51:49 +0100 Subject: [PATCH] Instantiate logger after parsing log.level command-line flag promlogConfig does not need to be a global var either. Signed-off-by: Daniel Swarbrick --- main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index ef73b7d..d8303ff 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( "os/signal" "syscall" + "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -48,8 +49,7 @@ var ( } reloadCh chan chan error - promlogConfig = &promlog.Config{} - logger = promlog.New(promlogConfig) + logger log.Logger ) func remoteIPMIHandler(w http.ResponseWriter, r *http.Request) { @@ -94,10 +94,12 @@ func updateConfiguration(w http.ResponseWriter, r *http.Request) { } func main() { + promlogConfig := &promlog.Config{} flag.AddFlags(kingpin.CommandLine, promlogConfig) kingpin.HelpFlag.Short('h') kingpin.Version(version.Print("ipmi_exporter")) kingpin.Parse() + logger = promlog.New(promlogConfig) _ = level.Info(logger).Log("msg", "Starting ipmi_exporter", "version", version.Info()) // Bail early if the config is bad.