From be8001793bb4ffa24fdc41c02113acca2c764ff0 Mon Sep 17 00:00:00 2001 From: Salar Nosrati-Ershad Date: Sat, 15 Jun 2024 23:28:05 +0330 Subject: [PATCH 1/2] cmd: observe env for debug and bind the flag to it Signed-off-by: Salar Nosrati-Ershad --- flagd/cmd/root.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flagd/cmd/root.go b/flagd/cmd/root.go index c70638f9b..a9128601f 100644 --- a/flagd/cmd/root.go +++ b/flagd/cmd/root.go @@ -47,6 +47,10 @@ func init() { // Cobra supports persistent flags, which, if defined here, // will be global for your application. rootCmd.PersistentFlags().BoolVarP(&Debug, "debug", "x", false, "verbose logging") + // Bind the cobra flag to viper key + if err := viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug")); err != nil { + fmt.Fprintln(os.Stderr, "error when binding flags", err.Error()) + } rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.agent.yaml)") rootCmd.AddCommand(startCmd) rootCmd.AddCommand(versionCmd) @@ -69,6 +73,7 @@ func initConfig() { } viper.AutomaticEnv() // read in environment variables that match + Debug = viper.GetBool("debug") // If a config file is found, read it in. if err := viper.ReadInConfig(); err == nil { From b7526bd5c0da4d064a1a77baea23e8b1c5e6e76a Mon Sep 17 00:00:00 2001 From: Salar Nosrati-Ershad Date: Mon, 17 Jun 2024 16:03:14 +0330 Subject: [PATCH 2/2] docs: add debug env variable to troubleshooting doc Signed-off-by: Salar Nosrati-Ershad --- docs/troubleshooting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index f3908cf27..6537d81f1 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -9,7 +9,7 @@ description: troubleshooting flagd If a flag or targeting rule isn't proceeding the way you'd expect, you may want to enable more verbose logging. flagd and flagd providers typically have debug or verbose logging modes that you can use for this sort of troubleshooting. -You can do this in the standalone version of flagd by starting it with the `--debug` flag (see [CLI](./reference/flagd-cli/flagd.md) for more information). +You can do this in the standalone version of flagd by starting it with the `--debug` flag (see [CLI](./reference/flagd-cli/flagd.md) for more information) or through `FLAGD_DEBUG` env variable. _In-process_ providers which embed the flag evaluation engine use a logging consistent with their implementation language and SDK. See your provider's documentation for details on how to enable verbose logging.