diff --git a/cmd/root.go b/cmd/root.go index 486bbfc4..486a35f2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -355,7 +355,7 @@ func init() { cobra.OnInitialize(initConfig) // General Config - rootCmd.PersistentFlags().StringVar(&logLevel, "log", "error", "Set the log level. Valid values: panic, fatal, error, warn, info, debug, trace") + rootCmd.PersistentFlags().StringVar(&logLevel, "log", "info", "Set the log level. Valid values: panic, fatal, error, warn, info, debug, trace") cobra.CheckErr(viper.BindEnv("log", "OVERMIND_LOG", "LOG")) // fallback to global config // Support API Keys in the environment @@ -398,8 +398,8 @@ func init() { if logLevel != "" { lvl, err = log.ParseLevel(logLevel) if err != nil { - log.WithFields(log.Fields{"level": logLevel, "err": err}).Errorf("couldn't parse `log` config, defaulting to `error`") - lvl = log.ErrorLevel + log.WithFields(log.Fields{"level": logLevel, "err": err}).Errorf("couldn't parse `log` config, defaulting to `info`") + lvl = log.InfoLevel } } else { lvl = log.ErrorLevel diff --git a/cmd/terraform_plan.go b/cmd/terraform_plan.go index 8cbfeb64..1a070114 100644 --- a/cmd/terraform_plan.go +++ b/cmd/terraform_plan.go @@ -83,6 +83,9 @@ func CmdWrapper(action string, requiredScopes []string, commandModel func([]stri defer span.End() defer tracing.LogRecoverToExit(ctx, cmdName) + // ensure that only error messages are printed to the console, + // disrupting bubbletea rendering (and potentially getting overwritten). + // Otherwise, when TEABUG is set, log to a file. if len(os.Getenv("TEABUG")) > 0 { f, err := tea.LogToFile("teabug.log", "debug") if err != nil { @@ -91,6 +94,8 @@ func CmdWrapper(action string, requiredScopes []string, commandModel func([]stri } defer f.Close() log.SetOutput(f) + } else { + log.SetLevel(log.ErrorLevel) } // wrap the rest of the function in a closure to allow for cleaner error handling and deferring.