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

Support JSON logging #328

Merged
merged 4 commits into from
Jul 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions cmd/promxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type cliOpts struct {
BindAddr string `long:"bind-addr" description:"address for promxy to listen on" default:":8082"`
ConfigFile string `long:"config" description:"path to the config file" default:"config.yaml"`
LogLevel string `long:"log-level" description:"Log level" default:"info"`
LogFormat string `long:"log-format" description:"Log format(text|json)" default:"text"`

WebReadTimeout time.Duration `long:"web.read-timeout" description:"Maximum duration before timing out read of the request, and closing idle connections." default:"5m"`

Expand Down Expand Up @@ -154,10 +155,17 @@ func main() {
}
logrus.SetLevel(level)

// Set the log format to have a reasonable timestamp
formatter := &logrus.TextFormatter{
FullTimestamp: true,
var formatter logrus.Formatter
switch opts.LogFormat {
case "json":
formatter = &logrus.JSONFormatter{}
ustuzhanin marked this conversation as resolved.
Show resolved Hide resolved
default:
// Set the log format to have a reasonable timestamp
formatter = &logrus.TextFormatter{
FullTimestamp: true,
}
}

logrus.SetFormatter(formatter)

// Above level 6, the k8s client would log bearer tokens in clear-text.
Expand Down