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

karma: add ability to configure log format #731

Merged
merged 3 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func init() {
pflag.Bool("log.config", true, "Log used configuration to log on startup")
pflag.String("log.level", "info",
"Log level, one of: debug, info, warning, error, fatal and panic")
pflag.String("log.format", "text",
"Log format, one of: text, json")

pflag.StringSlice("receivers.keep", []string{},
"List of receivers to keep, all alerts with different receivers will be ignored")
Expand Down Expand Up @@ -159,6 +161,7 @@ func (config *configSchema) Read() {
config.Listen.Prefix = v.GetString("listen.prefix")
config.Log.Config = v.GetBool("log.config")
config.Log.Level = v.GetString("log.level")
config.Log.Format = v.GetString("log.format")
config.Receivers.Keep = v.GetStringSlice("receivers.keep")
config.Receivers.Strip = v.GetStringSlice("receivers.strip")
config.Sentry.Private = v.GetString("sentry.private")
Expand Down
1 change: 1 addition & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ listen:
log:
config: true
level: info
format: text
jira: []
receivers:
keep: []
Expand Down
1 change: 1 addition & 0 deletions internal/config/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type configSchema struct {
Log struct {
Config bool
Level string
Format string
}
JIRA []jiraRule
Receivers struct {
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ func setupLogger() {
default:
log.Fatalf("Unknown log level '%s'", config.Config.Log.Level)
}

switch config.Config.Log.Format {
case "text":
log.SetFormatter(&log.TextFormatter{})
case "json":
log.SetFormatter(&log.JSONFormatter{})
default:
log.Fatalf("Unknown log format '%s'", config.Config.Log.Format)
}
}

func main() {
Expand Down