From d023222f49a57c658ab57090631a98eadb2cdaaa Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Mon, 14 Aug 2023 13:02:01 -0400 Subject: [PATCH] pass logger to dotenv --- cobrautil.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cobrautil.go b/cobrautil.go index 07ebdfc..8e097cf 100644 --- a/cobrautil.go +++ b/cobrautil.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/go-logr/logr" "github.com/joho/godotenv" "github.com/jzelinskie/stringz" "github.com/spf13/cobra" @@ -56,9 +57,13 @@ func SyncViperPreRunE(prefix string) CobraRunFunc { // // If empty, envfilePath defaults to ".env". // The .dotenv file is loaded first before any additional Viper behavior. -func SyncViperDotEnvPreRunE(prefix string, envfilePath string) CobraRunFunc { +func SyncViperDotEnvPreRunE(prefix, envfilePath string, l logr.Logger) CobraRunFunc { if err := godotenv.Load(stringz.DefaultEmpty(envfilePath, ".env")); err != nil { - fmt.Printf("Info: attempt to load env vars from config file at path: %s failed due to error: %s. Continue without loading it.\n", envfilePath, err) + l.Info( + "skipped loading dotenv", + "path", envfilePath, + "err", err, + ) } return SyncViperPreRunE(prefix) }