diff --git a/README.md b/README.md index d424e177..7b9f5317 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,8 @@ kubectl apply -f https://raw.githubusercontent.com/abahmed/kwatch/v0.8.5/deploy/ | `app.proxyURL` | used in outgoing http(s) requests except Kubernetes requests to cluster optionally | | `app.clusterName` | used in notifications to indicate which cluster has issue | | `app.disableStartupMessage` | If set to true, welcome message will not be sent to notification channels | +| `app.logFormatter` | used for setting custom formatter when app prints logs: text, json (default: text) | + ### Upgrader @@ -201,7 +203,7 @@ If you want to enable Microsoft Teams, provide the channel webhook. |:---------------------------------|:------------------------------------------------| | `alert.teams.webhook` | webhook Microsoft team | | `alert.teams.title` | Customized title in Microsoft teams message | -| `alert.teams.text` | Customized title in Microsoft teams message | +| `alert.teams.text` | Customized title in Microsoft teams message | #### Rocket Chat diff --git a/config/config.go b/config/config.go index 02521b70..a826982a 100644 --- a/config/config.go +++ b/config/config.go @@ -72,6 +72,9 @@ type App struct { // DisableUpdateCheck if set to true, welcome message will not be // sent to configured notification channels DisableStartupMessage bool `yaml:"disableStartupMessage"` + + // LogFormatter used for setting custom formatter when app prints logs + LogFormatter string `yaml:"logFormatter"` } // Upgrader confing struct diff --git a/config/defaultConfig.go b/config/defaultConfig.go index 0957a3dd..618c51f1 100644 --- a/config/defaultConfig.go +++ b/config/defaultConfig.go @@ -2,6 +2,9 @@ package config func DefaultConfig() *Config { return &Config{ + App: App{ + LogFormatter: "text", + }, IgnoreFailedGracefulShutdown: true, PvcMonitor: PvcMonitor{ Enabled: true, diff --git a/main.go b/main.go index 15dc82b5..c6bbffcb 100644 --- a/main.go +++ b/main.go @@ -18,12 +18,13 @@ import ( ) func main() { - logrus.Infof(fmt.Sprintf(constant.WelcomeMsg, version.Short())) - config, err := config.LoadConfig() if err != nil { logrus.Fatalf("failed to load config: %s", err.Error()) } + setLogFormatter(config.App.LogFormatter) + + logrus.Infof(fmt.Sprintf(constant.WelcomeMsg, version.Short())) // create kubernetes client client := client.Create(&config.App) @@ -61,3 +62,12 @@ func main() { // start watcher watcher.Start(client, namespace, h.ProcessPod) } + +func setLogFormatter(formatter string) { + switch formatter { + case "json": + logrus.SetFormatter(&logrus.JSONFormatter{}) + default: + logrus.SetFormatter(&logrus.TextFormatter{}) + } +}