From ef55e5bc1645544f735fd907ea2688b3363b24e1 Mon Sep 17 00:00:00 2001 From: Srinivas Bommadevara Date: Thu, 27 Jun 2024 10:06:27 +0200 Subject: [PATCH] Optional flag to enable logging in json format --- cmd/topicctl/subcmd/root.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/topicctl/subcmd/root.go b/cmd/topicctl/subcmd/root.go index ad691b54..0c6cf237 100644 --- a/cmd/topicctl/subcmd/root.go +++ b/cmd/topicctl/subcmd/root.go @@ -12,6 +12,7 @@ import ( var debug bool var noSpinner bool +var jsonOutput bool // RootCmd is the cobra CLI root command. var RootCmd = &cobra.Command{ @@ -40,6 +41,12 @@ func init() { false, "disable all UI spinners", ) + RootCmd.PersistentFlags().BoolVar( + &jsonOutput, + "json-output", + false, + "enable logging in json format", + ) } // Execute runs topicctl. @@ -56,5 +63,8 @@ func preRun(cmd *cobra.Command, args []string) error { if debug { log.SetLevel(log.DebugLevel) } + if jsonOutput{ + log.SetFormatter(&log.JSONFormatter{}) + } return nil }