Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use default logging before parsing cli args #204

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cmd/terramate/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const (
defaultBranchBaseRef = "HEAD^"
)

const (
defaultLogLevel = "info"
defaultLogFmt = "console"
)

type cliSpec struct {
Version struct{} `cmd:"" help:"Terramate version."`
Chdir string `short:"C" optional:"true" help:"sets working directory."`
Expand Down Expand Up @@ -119,6 +124,7 @@ func Exec(
stdout io.Writer,
stderr io.Writer,
) {
configureLogging(defaultLogLevel, defaultLogFmt, stderr)
c := newCLI(args, stdin, stdout, stderr)
c.run()
}
Expand Down Expand Up @@ -198,6 +204,11 @@ func newCLI(
}

configureLogging(parsedArgs.LogLevel, parsedArgs.LogFmt, stderr)
// If we don't re-create the logger after configuring we get some
// log entries with a mix of default fmt and selected fmt.
logger = log.With().
Str("action", "newCli()").
Logger()

if ctx.Command() == "version" {
logger.Debug().
Expand Down