Skip to content

Commit

Permalink
Log improvements (#3338)
Browse files Browse the repository at this point in the history
* chore: Hiding mocks tests

* fix: Removing terratest log parser

* fix: Moving mocks generation

* fix: Fixing mock tests again

* fix: Still need mockery for unit tests, it seems

* chore: Adding `performance` preset to lints

* chore: Addressing lint errors

* fix: Resolving weird conflict from merge

* fix: Fixing `TestTerragruntProviderCacheMultiplePlatforms` test

* fix: Fixing copy bug in arg optimization

* chore: log formatter

* fix: lint

* chore: disable log formatting for output command

* chore: code improvements

* fix: tests

* chore: log formatting improvements

* chore: different prefix colors for modules

* chore: fix tests

* chore: fix tests

* chore: fix tests

* chore: disable log formatting for circleci

* chore: fix tests

* chore: fix tests

* chore: fix tests

* chore: fix tests

* chore: fix tests

* chore: fix tests

* chore: relative path as prefix

* chore: fix unit test

* chore: fix lint

* chore: fix integration tests

* chore: docs updated, deprecated falgs

* fix: const names

* fix: const name

* fix: const name

* fix: arg name

* fix: temproray solution for TestTableTagging

* chore: add log integration tests

* fix: logs

* fix: test

* chore: disable strict_lint

* chore: enable strict_lint

* chore: code improvements

* fix: tests

* fix: concurrent map writes

* fix: lint errors

* chore: add tf stdout notifier

* fix: lint

* chore: code improvements

* chore: log message level

* chore: rename flag name

* fix: json nested in json

* fix: std buf

* fix: run shell cmd

* fix: run shell cmd

* chore: rename func

* fix: lint

* chore: code improvements

* chore: docs updating

* fix: lint

* fix: docs styling

* fix: reset terminal style for TF output

* fix: reset TF styles

---------

Co-authored-by: Yousif Akbar <[email protected]>
  • Loading branch information
levkohimins and yhakbar committed Aug 27, 2024
1 parent 8fac874 commit db752bf
Show file tree
Hide file tree
Showing 72 changed files with 1,778 additions and 552 deletions.
49 changes: 24 additions & 25 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"path/filepath"
"sort"
"strings"
"time"

"github.com/gruntwork-io/terragrunt/engine"
Expand Down Expand Up @@ -44,9 +43,9 @@ import (
terraformCmd "github.com/gruntwork-io/terragrunt/cli/commands/terraform"
terragruntinfo "github.com/gruntwork-io/terragrunt/cli/commands/terragrunt-info"
validateinputs "github.com/gruntwork-io/terragrunt/cli/commands/validate-inputs"
"github.com/gruntwork-io/terragrunt/internal/log"
"github.com/gruntwork-io/terragrunt/options"
"github.com/gruntwork-io/terragrunt/pkg/cli"
"github.com/gruntwork-io/terragrunt/pkg/log"
)

// forced shutdown interval after receiving an interrupt signal
Expand Down Expand Up @@ -78,7 +77,7 @@ func NewApp(writer io.Writer, errWriter io.Writer) *App {

app.Flags = append(
commands.NewGlobalFlags(opts),
commands.NewHelpVersionFlags(opts)...)
NewDeprecatedFlags(opts)...)

app.Commands = append(
DeprecatedCommands(opts),
Expand Down Expand Up @@ -289,16 +288,14 @@ func initialSetup(cliCtx *cli.Context, opts *options.TerragruntOptions) error {
util.DisableLogColors()
}

if opts.DisableLogFormatting {
util.DisableLogFormatting()
}

if opts.JsonLogFormat {
util.JsonFormat()
}

opts.LogLevel = util.ParseLogLevel(opts.LogLevelStr)
opts.Logger = util.CreateLogEntry("", opts.LogLevel)
opts.Logger.Logger.SetOutput(cliCtx.App.ErrWriter)

log.SetLogger(opts.Logger.Logger)

// --- Working Dir
if opts.WorkingDir == "" {
currentDir, err := os.Getwd()
Expand All @@ -311,6 +308,13 @@ func initialSetup(cliCtx *cli.Context, opts *options.TerragruntOptions) error {

opts.WorkingDir = filepath.ToSlash(opts.WorkingDir)

workingDir, err := filepath.Abs(opts.WorkingDir)
if err != nil {
return errors.WithStackTrace(err)
}

opts.RootWorkingDir = filepath.ToSlash(workingDir)

// --- Download Dir
if opts.DownloadDir == "" {
opts.DownloadDir = util.JoinPath(opts.WorkingDir, util.TerragruntCacheDir)
Expand All @@ -323,6 +327,12 @@ func initialSetup(cliCtx *cli.Context, opts *options.TerragruntOptions) error {

opts.DownloadDir = filepath.ToSlash(downloadDir)

opts.LogLevel = util.ParseLogLevel(opts.LogLevelStr)
opts.Logger = util.CreateLogEntry("", opts.LogLevel, nil, opts.DisableLogColors, opts.DisableLogFormatting)
opts.Logger.Logger.SetOutput(cliCtx.App.ErrWriter)

log.SetLogger(opts.Logger.Logger)

// --- Terragrunt ConfigPath
if opts.TerragruntConfigPath == "" {
opts.TerragruntConfigPath = config.GetDefaultConfigPath(opts.WorkingDir)
Expand All @@ -335,6 +345,11 @@ func initialSetup(cliCtx *cli.Context, opts *options.TerragruntOptions) error {
return errors.WithStackTrace(err)
}

opts.RelativeTerragruntConfigPath, err = util.GetPathRelativeToWithSeparator(opts.TerragruntConfigPath, opts.RootWorkingDir)
if err != nil {
return err
}

opts.TerraformPath = filepath.ToSlash(opts.TerraformPath)

opts.ExcludeDirs, err = util.GlobCanonicalPath(opts.WorkingDir, opts.ExcludeDirs...)
Expand Down Expand Up @@ -372,22 +387,6 @@ func initialSetup(cliCtx *cli.Context, opts *options.TerragruntOptions) error {
// Log the terragrunt version in debug mode. This helps with debugging issues and ensuring a specific version of terragrunt used.
opts.Logger.Debugf("Terragrunt Version: %s", opts.TerragruntVersion)

// --- IncludeModulePrefix
jsonOutput := false

for _, arg := range opts.TerraformCliArgs {
if strings.EqualFold(arg, "-json") {
jsonOutput = true
break
}
}

if opts.IncludeModulePrefix && !jsonOutput {
opts.OutputPrefix = fmt.Sprintf("[%s] ", opts.WorkingDir)
} else {
opts.IncludeModulePrefix = false
}

// --- Others
if !opts.RunAllAutoApprove {
// When running in no-auto-approve mode, set parallelism to 1 so that interactive prompts work.
Expand Down
4 changes: 2 additions & 2 deletions cli/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ func runAppTest(args []string, opts *options.TerragruntOptions) (*options.Terrag
app.Writer = &bytes.Buffer{}
app.ErrWriter = &bytes.Buffer{}
app.Flags = append(
commands.NewGlobalFlags(opts),
commands.NewHelpVersionFlags(opts)...)
cli.NewDeprecatedFlags(opts),
commands.NewGlobalFlags(opts)...)
app.Commands = append(
cli.DeprecatedCommands(opts),
terragruntCommands...).WrapAction(cli.WrapWithTelemetry(opts))
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/catalog/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/gruntwork-io/terragrunt/cli/commands/catalog/module"
"github.com/gruntwork-io/terragrunt/cli/commands/catalog/tui"
"github.com/gruntwork-io/terragrunt/config"
"github.com/gruntwork-io/terragrunt/internal/log"
"github.com/gruntwork-io/terragrunt/options"
"github.com/gruntwork-io/terragrunt/pkg/log"
"github.com/gruntwork-io/terragrunt/util"
)

Expand Down
2 changes: 1 addition & 1 deletion cli/commands/catalog/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/gruntwork-io/go-commons/collections"
"github.com/gruntwork-io/go-commons/errors"
"github.com/gruntwork-io/terragrunt/pkg/log"
"github.com/gruntwork-io/terragrunt/internal/log"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/catalog/module/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gitsight/go-vcsurl"
"github.com/gruntwork-io/go-commons/errors"
"github.com/gruntwork-io/go-commons/files"
"github.com/gruntwork-io/terragrunt/pkg/log"
"github.com/gruntwork-io/terragrunt/internal/log"
"github.com/gruntwork-io/terragrunt/terraform"
"github.com/hashicorp/go-getter"
"gopkg.in/ini.v1"
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/catalog/tui/command/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/gruntwork-io/terragrunt/cli/commands/catalog/module"

"github.com/gruntwork-io/terragrunt/cli/commands/scaffold"
"github.com/gruntwork-io/terragrunt/internal/log"
"github.com/gruntwork-io/terragrunt/options"
"github.com/gruntwork-io/terragrunt/pkg/log"
)

type Scaffold struct {
Expand Down
Loading

0 comments on commit db752bf

Please sign in to comment.