Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to github.com/prometheus/common/promlog for logging #71

Merged
merged 2 commits into from
Jun 23, 2021

Conversation

johanfleury
Copy link
Contributor

This PR change logging framework from github.com/prometheus/common/log to github.com/prometheus/common/promlog as the former was removed in v0.27.0.

This changes quite a few things, especially the log format:

$ go run ssl_exporter.go
INFO[0000] Starting ssl_exporter (version=, branch=, revision=)  source="ssl_exporter.go:130"
INFO[0000] Build context (go=go1.15.13, user=, date=)    source="ssl_exporter.go:131"
INFO[0000] Listening on :9219                            source="ssl_exporter.go:148"
^Csignal: interrupt

$ go run ssl_exporter.go
ts=2021-06-10T18:20:51.579Z caller=log.go:168 level=info msg="Starting ssl_exporter (version=, branch=, revision=)"
ts=2021-06-10T18:20:51.579Z caller=log.go:168 level=info msg="Build context (go=go1.15.13, user=, date=)"
ts=2021-06-10T18:20:51.579Z caller=log.go:168 level=info msg="Listening on :9219"
^Csignal: interrupt

$ go run ssl_exporter.go --log.format=json
{"caller":"log.go:168","level":"info","msg":"Starting ssl_exporter (version=, branch=, revision=)","ts":"2021-06-10T20:11:19.128Z"}
{"caller":"log.go:168","level":"info","msg":"Build context (go=go1.15.13, user=, date=)","ts":"2021-06-10T20:11:19.129Z"}
{"caller":"log.go:168","level":"info","msg":"Listening on :9219","ts":"2021-06-10T20:11:19.129Z"}
^Csignal: interrupt

Sending a log to a specific level requires to use the go-kit/log/level module with the following syntax: level.<Level>(logger).Log(...).

go-kit/log provides structured logs and I tried to use existing keys that were already used.

prober/file_test.go Outdated Show resolved Hide resolved
prober/file.go Outdated Show resolved Hide resolved
Copy link
Owner

@ribbybibby ribbybibby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I've left a few comments but lgtm in general.

@johanfleury johanfleury force-pushed the feature/move-to-promlog branch 2 times, most recently from 3230c46 to bfdbf41 Compare June 11, 2021 13:49
@johanfleury
Copy link
Contributor Author

Thanks for the reviewing so quickly :) I think fixed what you asked.

I created a new file (prober/test.go) to put the newTestLogger function, let me know if that’s ok.

@ribbybibby ribbybibby merged commit 83f0127 into ribbybibby:master Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants