Skip to content

Commit

Permalink
Revert default log level to info
Browse files Browse the repository at this point in the history
... instead force log level when running bubbletea and allow redirection
to a file.
  • Loading branch information
DavidS-ovm committed Apr 11, 2024
1 parent 28d58ca commit cd341d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cmd/terraform_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down

0 comments on commit cd341d0

Please sign in to comment.