From 1daee323a3cf46229370617f69766088f2eabbb4 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Sun, 7 May 2017 04:38:31 -0400 Subject: [PATCH] cmd/chihaya: add --json flag This flag enables logging as JSON. --- cmd/chihaya/main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/chihaya/main.go b/cmd/chihaya/main.go index 8ba84ab..af58710 100644 --- a/cmd/chihaya/main.go +++ b/cmd/chihaya/main.go @@ -183,6 +183,11 @@ func main() { Short: "BitTorrent Tracker", Long: "A customizable, multi-protocol BitTorrent Tracker", PersistentPreRun: func(cmd *cobra.Command, args []string) { + jsonLog, _ := cmd.Flags().GetBool("json") + if jsonLog { + log.SetFormatter(&log.JSONFormatter{}) + } + debugLog, _ := cmd.Flags().GetBool("debug") if debugLog { log.Info("enabling debug logging") @@ -194,6 +199,7 @@ func main() { rootCmd.Flags().String("config", "/etc/chihaya.yaml", "location of configuration file") rootCmd.Flags().String("cpuprofile", "", "location to save a CPU profile") rootCmd.Flags().Bool("debug", false, "enable debug logging") + rootCmd.Flags().Bool("json", false, "enable json logging") if err := rootCmd.Execute(); err != nil { log.Fatal("failed when executing root cobra command: " + err.Error())