Skip to content

Commit

Permalink
Fix logging (#526)
Browse files Browse the repository at this point in the history
The logger was created before reading the flags and the format/level
didn't have any effect
  • Loading branch information
lucacome authored Oct 25, 2023
1 parent c828e64 commit ed87722
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,22 @@ const exporterName = "nginx_exporter"
func main() {
kingpin.Flag("prometheus.const-label", "Label that will be used in every metric. Format is label=value. It can be repeated multiple times.").Envar("CONST_LABELS").StringMapVar(&constLabels)

promlogConfig := &promlog.Config{}
logger := promlog.New(promlogConfig)

// convert deprecated flags to new format
for i, arg := range os.Args {
if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") && len(arg) > 2 {
newArg := fmt.Sprintf("-%s", arg)
level.Warn(logger).Log("msg", "the flag format is deprecated and will be removed in a future release, please use the new format", "old", arg, "new", newArg)
fmt.Printf("the flag format is deprecated and will be removed in a future release, please use the new format: %s\n", newArg)
os.Args[i] = newArg
}
}

promlogConfig := &promlog.Config{}

flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print(exporterName))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger := promlog.New(promlogConfig)

level.Info(logger).Log("msg", "Starting nginx-prometheus-exporter", "version", version.Info())
level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext())
Expand Down

0 comments on commit ed87722

Please sign in to comment.