Skip to content

Commit

Permalink
Merge pull request #182 from dswarbrick/log-level
Browse files Browse the repository at this point in the history
Make log level configurable via command-line flag
  • Loading branch information
SuperQ authored Aug 23, 2023
2 parents b9e01ef + d30f59b commit 5195bb3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *XMLClient) Get(p string, v interface{}) error {
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("unexpected status %s", resp.Status)
return fmt.Errorf("unexpected status for %q: %s", u, resp.Status)
}

if err := xml.NewDecoder(resp.Body).Decode(v); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion bind/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (c *Client) Get(p string, v interface{}) error {
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("unexpected status %s", resp.Status)
return fmt.Errorf("unexpected status for %q: %s", u, resp.Status)
}

if err := json.NewDecoder(resp.Body).Decode(v); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion bind_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus-community/bind_exporter/bind"
"github.com/prometheus-community/bind_exporter/bind/auto"
Expand All @@ -35,6 +36,7 @@ import (
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
Expand All @@ -47,7 +49,7 @@ const (
)

var (
logger = promlog.New(&promlog.Config{})
logger = log.NewNopLogger()

up = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "up"),
Expand Down Expand Up @@ -551,9 +553,12 @@ func main() {
bind.ServerStats, bind.ViewStats, bind.TaskStats,
}).String()).SetValue(&groups)

promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print(exporter))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger = promlog.New(promlogConfig)

level.Info(logger).Log("msg", "Starting bind_exporter", "version", version.Info())
level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext())
Expand Down

0 comments on commit 5195bb3

Please sign in to comment.