Skip to content

Commit

Permalink
promlog.New changed signature
Browse files Browse the repository at this point in the history
Fixes invalid type being passes to the constructor:

```
cannot use &allowedLevel (type *promlog.AllowedLevel) as type *promlog.Config in argument to flag.AddFlags
```

See following for more info: prometheus/common#136
  • Loading branch information
razius committed Jan 1, 2019
1 parent f0eee24 commit 7cee554
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Flags:
--config="domains.yml" Domain exporter configuration file.
--bind=":9203" The address to listen on for HTTP requests.
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
--version Show application version.
```

Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ var (
"2006-01-02 15:04:05",
}

allowedLevel promlog.AllowedLevel
logger log.Logger
config promlog.Config
logger log.Logger
)

type Config struct {
Domains []string `yaml:"domains"`
}

func main() {
flag.AddFlags(kingpin.CommandLine, &allowedLevel)
flag.AddFlags(kingpin.CommandLine, &config)
kingpin.Version(version.Print("domain_exporter"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()

logger = promlog.New(allowedLevel)
logger = promlog.New(&config)

level.Info(logger).Log("msg", "Starting domain_exporter", "version", version.Info())
level.Info(logger).Log("msg", "Build context", version.BuildContext())
Expand Down
12 changes: 9 additions & 3 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ import (
)

func init() { // so we don't panic
level := promlog.AllowedLevel{}
level.Set("info")
logger = promlog.New(level)
allowedLevel := promlog.AllowedLevel{}
allowedLevel.Set("debug")
allowedFormat := promlog.AllowedFormat{}
allowedFormat.Set("logfmt")
promlogConfig := promlog.Config{
Level: &allowedLevel,
Format: &allowedFormat,
}
logger = promlog.New(&promlogConfig)
}

func TestParsing(t *testing.T) {
Expand Down

0 comments on commit 7cee554

Please sign in to comment.