ribbybibby / ssl_exporter

Exports Prometheus metrics for TLS certificates
Apache License 2.0
507 stars 95 forks source link

The `log.level` flag has no effects since version 2.2.1 (#71) #75

Closed johanfleury closed 2 years ago

johanfleury commented 3 years ago

Since version 2.2.1 was released (with PR #71 of which I am the author), the log.level flag has no effects and all logs are printed regardless of there level

I can’t figure out where the issue is and I can’t reproduce with this simple test code:

package main

import (
    "github.com/go-kit/log"
    "github.com/go-kit/log/level"
    "github.com/prometheus/common/promlog"
    promlogflag "github.com/prometheus/common/promlog/flag"
    "gopkg.in/alecthomas/kingpin.v2"
)

func main() {
    promlogConfig := promlog.Config{}

    promlogflag.AddFlags(kingpin.CommandLine, &promlogConfig)
    kingpin.HelpFlag.Short('h')
    kingpin.Parse()

    logger := promlog.New(&promlogConfig)

    foo(logger)
}

func foo(logger log.Logger) {
    level.Error(logger).Log("msg", "error")
    level.Info(logger).Log("msg", "info")
    level.Debug(logger).Log("msg", "debug")
}

promlogConfig.Level is correctly set to the log level passed on the command line (or info by default).

Adding level.NewFilter(logger, level.AllowInfo()) after line 129 in ssl_exporter.go seems to work and correctly filter debug messages, but setting the promlog.Config manually also has no effect:

    allowedLevel := promlog.AllowedLevel{}
    allowedLevel.Set("info")

    promlogConfig = promlog.Config{
        Level: &allowedLevel,
    }

    logger := promlog.New(&promlogConfig)

Any idea with this happens in ssl_exporter?