Skip to content

Commit

Permalink
Change the default logging level
Browse files Browse the repository at this point in the history
Modify the logging level of many calls to make it more significant (including using the debug level)
  • Loading branch information
jocgir committed Jul 30, 2017
1 parent 6a308e7 commit 40aee93
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 51 deletions.
12 changes: 6 additions & 6 deletions cli/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func parseTerragruntOptionsFromArgs(args []string) (*options.TerragruntOptions,
}
opts.TerraformCliArgs = filterVarsAndVarFiles(cmd, opts, opts.TerraformCliArgs)

err = util.InitLogging(loggingLevel, logging.INFO, !util.ListContainsElement(opts.TerraformCliArgs, "-no-color"))
err = util.InitLogging(loggingLevel, logging.NOTICE, !util.ListContainsElement(opts.TerraformCliArgs, "-no-color"))
return opts, err
}

Expand Down Expand Up @@ -152,7 +152,7 @@ func filterTerraformExtraArgs(terragruntOptions *options.TerragruntOptions, terr
for _, file := range util.RemoveDuplicatesFromListKeepLast(arg.RequiredVarFiles) {
file = config.SubstituteVars(file, terragruntOptions)
importTfVarFile(terragruntOptions, file, options.VarFile)
terragruntOptions.Logger.Infof("Importing %s", file)
terragruntOptions.Logger.Info("Importing", file)
if currentCommandIncluded {
out = append(out, fmt.Sprintf("-var-file=%s", file))
}
Expand All @@ -166,10 +166,10 @@ func filterTerraformExtraArgs(terragruntOptions *options.TerragruntOptions, terr
if currentCommandIncluded {
out = append(out, fmt.Sprintf("-var-file=%s", file))
}
terragruntOptions.Logger.Infof("Importing %s", file)
terragruntOptions.Logger.Info("Importing", file)
importTfVarFile(terragruntOptions, file, options.VarFile)
} else if currentCommandIncluded {
terragruntOptions.Logger.Infof("Skipping var-file %s as it does not exist", file)
terragruntOptions.Logger.Debugf("Skipping var-file %s as it does not exist", file)
}
}
}
Expand All @@ -181,7 +181,7 @@ func parseEnvironmentVariables(terragruntOptions *options.TerragruntOptions, env
const tfPrefix = "TF_VAR_"
for i := 0; i < len(environment); i++ {
if key, value, err := splitVariable(environment[i]); err != nil {
terragruntOptions.Logger.Warningf("Environment variable ignored: %v", err)
terragruntOptions.Logger.Warning("Environment variable ignored:", environment[i], err)
} else {
terragruntOptions.Env[key] = value
// All environment variables starting with TF_ENV_ are considered as variables
Expand Down Expand Up @@ -227,7 +227,7 @@ func filterVarsAndVarFiles(command string, terragruntOptions *options.Terragrunt
for i := 0; i < len(args); i++ {
if args[i] == varArg && i+1 < len(args) {
if key, value, err := splitVariable(args[i+1]); err != nil {
terragruntOptions.Logger.Warningf("-var ignored: %v", err)
terragruntOptions.Logger.Warning("-var ignored:", args[i+1], err)
} else {
terragruntOptions.Variables.SetValue(key, value, options.VarParameterExplicit)
}
Expand Down
10 changes: 5 additions & 5 deletions cli/cli_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func runTerragrunt(terragruntOptions *options.TerragruntOptions) (result error)
return err
}

if conf.Terraform != nil && conf.Terraform.ExtraArgs != nil && len(conf.Terraform.ExtraArgs) > 0 {
if conf.Terraform != nil && len(conf.Terraform.ExtraArgs) > 0 {
commandLength := 1
if util.ListContainsElement(TERRAFORM_COMMANDS_WITH_SUBCOMMAND, terragruntOptions.TerraformCliArgs[0]) {
commandLength = 2
Expand Down Expand Up @@ -273,7 +273,7 @@ func runTerragrunt(terragruntOptions *options.TerragruntOptions) (result error)

// Check if we must configure environment variables to assume a distinct role when applying external commands.
if conf.AssumeRole != nil && *conf.AssumeRole != "" {
terragruntOptions.Logger.Noticef("Assuming role %s", *conf.AssumeRole)
terragruntOptions.Logger.Notice("Assuming role", *conf.AssumeRole)
if err := setRoleEnvironmentVariables(terragruntOptions, *conf.AssumeRole); err != nil {
return err
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func runTerragrunt(terragruntOptions *options.TerragruntOptions) (result error)
// terraform init if it was necessary, and the below RunTerraformCommand would end up calling init without
// the correct remote state arguments, which is confusing.
if terragruntOptions.TerraformCliArgs[0] == CMD_INIT {
terragruntOptions.Logger.Info("Running 'init' manually is not necessary: Terragrunt will call it automatically when needed before running other Terraform commands")
terragruntOptions.Logger.Warning("Running 'init' manually is not necessary: Terragrunt will call it automatically when needed before running other Terraform commands")
return nil
}

Expand Down Expand Up @@ -487,7 +487,7 @@ func destroyAll(terragruntOptions *options.TerragruntOptions) error {
return err
}

terragruntOptions.Logger.Noticef("%s", stack.String())
terragruntOptions.Logger.Notice(stack)
shouldDestroyAll, err := shell.PromptUserForYesNo("WARNING: Are you sure you want to run `terragrunt destroy` in each folder of the stack described above? There is no undo!", terragruntOptions)
if err != nil {
return err
Expand All @@ -508,7 +508,7 @@ func outputAll(terragruntOptions *options.TerragruntOptions) error {
return err
}

terragruntOptions.Logger.Notice(stack.String())
terragruntOptions.Logger.Notice(stack)
return stack.Output(terragruntOptions)
}

Expand Down
12 changes: 6 additions & 6 deletions cli/download_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ func downloadTerraformSource(source *TerraformSource, terragruntOptions *options
return err
}

terragruntOptions.Logger.Noticef("Copying files from %s into %s", terragruntOptions.WorkingDir, source.WorkingDir)
terragruntOptions.Logger.Debugf("Copying files from %s into %s", terragruntOptions.WorkingDir, source.WorkingDir)
if err := util.CopyFolderContents(terragruntOptions.WorkingDir, source.WorkingDir); err != nil {
return err
}

terragruntOptions.Logger.Noticef("Setting working directory to %s", source.WorkingDir)
terragruntOptions.Logger.Info("Setting working directory to", source.WorkingDir)
terragruntOptions.WorkingDir = source.WorkingDir

return nil
Expand All @@ -76,15 +76,15 @@ func downloadTerraformSourceIfNecessary(terraformSource *TerraformSource, terrag
}

if alreadyLatest {
terragruntOptions.Logger.Infof("Terraform files in %s are up to date. Will not download again.", terraformSource.WorkingDir)
terragruntOptions.Logger.Debugf("Terraform files in %s are up to date. Will not download again.", terraformSource.WorkingDir)
return nil
}

if err := cleanupTerraformFiles(terraformSource.DownloadDir, terragruntOptions); err != nil {
return err
}

terragruntOptions.Logger.Noticef("Downloading Terraform configurations from %s into %s", terraformSource.CanonicalSourceURL, terraformSource.DownloadDir)
terragruntOptions.Logger.Infof("Downloading Terraform configurations from %s into %s", terraformSource.CanonicalSourceURL, terraformSource.DownloadDir)
if err := module.GetCopy(terraformSource.DownloadDir, terraformSource.CanonicalSourceURL.String()); err != nil {
return err
}
Expand Down Expand Up @@ -267,7 +267,7 @@ func splitSourceUrl(sourceUrl *url.URL, terragruntOptions *options.TerragruntOpt
sourceUrlModifiedPath.Path = pathSplitOnDoubleSlash[0]
return sourceUrlModifiedPath, pathSplitOnDoubleSlash[1], nil
} else {
terragruntOptions.Logger.Noticef("No double-slash (//) found in source URL %s. Relative paths in downloaded Terraform code may not work.", sourceUrl.Path)
terragruntOptions.Logger.Debugf("No double-slash (//) found in source URL %s. Relative paths in downloaded Terraform code may not work.", sourceUrl.Path)
return sourceUrl, "", nil
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ func cleanupTerraformFiles(path string, terragruntOptions *options.TerragruntOpt
return nil
}

terragruntOptions.Logger.Infof("Cleaning up existing *.tf files in %s", path)
terragruntOptions.Logger.Info("Cleaning up existing *.tf files in", path)

files, err := zglob.Glob(util.JoinPath(path, "**/*.tf"))
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions cli/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func importFiles(terragruntOptions *options.TerragruntOptions, importers []confi

for _, importer := range importers {
if len(importer.OS) > 0 && !util.ListContainsElement(importer.OS, runtime.GOOS) {
terragruntOptions.Logger.Infof("Importer %s skipped, executed only on %v", importer.Name, importer.OS)
terragruntOptions.Logger.Debugf("Importer %s skipped, executed only on %v", importer.Name, importer.OS)
continue
}

Expand Down Expand Up @@ -89,7 +89,7 @@ func importFiles(terragruntOptions *options.TerragruntOptions, importers []confi
for i, file := range files {
fileBases[i] = filepath.Base(file)
}
terragruntOptions.Logger.Noticef("%s: Copy %s to %s", importer.Name, strings.Join(fileBases, ", "), folderName)
terragruntOptions.Logger.Infof("%s: Copy %s to %s", importer.Name, strings.Join(fileBases, ", "), folderName)
} else if importer.Required {
return fmt.Errorf("Unable to import required file %s", pattern)
}
Expand All @@ -104,20 +104,20 @@ func importFiles(terragruntOptions *options.TerragruntOptions, importers []confi
} else if importer.Required {
return fmt.Errorf("Unable to import required file %s", source)
} else if !isModule {
terragruntOptions.Logger.Warningf("Skipping copy of %s to %s, the source is not found", source, folderName)
terragruntOptions.Logger.Debugf("Skipping copy of %s to %s, the source is not found", source, folderName)
}
}

for _, source := range importer.CopyAndRenameFiles {
if util.FileExists(source.Source) {
terragruntOptions.Logger.Noticef("Copy file %s to %s/%v", filepath.Base(source.Source), folderName, source.Target)
terragruntOptions.Logger.Infof("Copy file %s to %s/%v", filepath.Base(source.Source), folderName, source.Target)
if err := copy(source.Source, source.Target); err != nil {
return err
}
} else if importer.Required {
return fmt.Errorf("Unable to import required file %s", source.Source)
} else if !isModule {
terragruntOptions.Logger.Warningf("Skipping copy of %s to %s, the source is not found", source, folderName)
terragruntOptions.Logger.Debugf("Skipping copy of %s to %s, the source is not found", source, folderName)
}
}
}
Expand All @@ -133,12 +133,12 @@ func runHooks(terragruntOptions *options.TerragruntOptions, hooks []config.Hook)
continue
}
if len(hook.OS) > 0 && !util.ListContainsElement(hook.OS, runtime.GOOS) {
terragruntOptions.Logger.Infof("Hook %s skipped, executed only on %v", hook.Name, hook.OS)
terragruntOptions.Logger.Debugf("Hook %s skipped, executed only on %v", hook.Name, hook.OS)
continue
}
hook.Command = strings.TrimSpace(hook.Command)
if len(hook.Command) == 0 {
terragruntOptions.Logger.Infof("Hook %s skipped, no command to execute", hook.Name)
terragruntOptions.Logger.Debugf("Hook %s skipped, no command to execute", hook.Name)
continue
}
cmd := shell.RunShellCommand
Expand Down Expand Up @@ -173,7 +173,7 @@ func getModulesFolders(terragruntOptions *options.TerragruntOptions) ([]string,
return nil, err
}
if !stat.IsDir() {
terragruntOptions.Logger.Warningf("Unexpected file in .terraform/modules: %s", module)
terragruntOptions.Logger.Warning("Unexpected file in .terraform/modules:", module)
continue
}

Expand Down
12 changes: 6 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func mergeConfigWithIncludedConfig(config *TerragruntConfig, includedConfig *Ter
// for _, extra := range original {
// for i, existing := range result {
// if existing.Name == extra.Name {
// terragruntOptions.Logger.Infof("Skipping extra_arguments %v as it is overridden in the current config", extra.Name)
// terragruntOptions.Logger.Debugf("Skipping extra_arguments %v as it is overridden in the current config", extra.Name)
// // For extra args, we want to keep the values specified in the child and put them after
// // the parent ones, so if we encounter a duplicate, we just overwrite it.
// result[i] = extra
Expand All @@ -488,7 +488,7 @@ addHook:
for _, hook := range original {
for i, existing := range result {
if existing.Name == hook.Name {
terragruntOptions.Logger.Infof("Skipping Hook %v as it is overridden in the current config", hook.Name)
terragruntOptions.Logger.Debug("Skipping Hook %v as it is overridden in the current config", hook.Name)
result[i] = hook
continue addHook
}
Expand All @@ -504,7 +504,7 @@ addHook:
for _, hook := range *newHooks {
for _, existing := range original {
if existing.Name == hook.Name {
terragruntOptions.Logger.Infof("Skipping Hook %v as it is overridden in the current config", hook.Name)
terragruntOptions.Logger.Debug("Skipping Hook %v as it is overridden in the current config", hook.Name)
continue addHook
}
}
Expand All @@ -519,7 +519,7 @@ add:
for _, command := range original {
for i, existing := range result {
if existing.Name == command.Name {
terragruntOptions.Logger.Infof("Skipping Extra Command %v as it is overridden in the current config", command.Name)
terragruntOptions.Logger.Debugf("Skipping Extra Command %v as it is overridden in the current config", command.Name)
result[i] = command
continue add
}
Expand All @@ -536,7 +536,7 @@ addImport:
for _, importer := range original {
for i, existing := range result {
if existing.Name == importer.Name {
terragruntOptions.Logger.Infof("Skipping ImportFiles %v as it is overridden in the current config", importer.Name)
terragruntOptions.Logger.Debugf("Skipping ImportFiles %v as it is overridden in the current config", importer.Name)
result[i] = importer
continue addImport
}
Expand All @@ -563,7 +563,7 @@ func mergeExtraArgs(terragruntOptions *options.TerragruntOptions, childExtraArgs
if parentExtraArgsWithSameName != -1 {
// If the parent contains an extra_arguments with the same name as the child,
// then override the parent's extra_arguments with the child's.
terragruntOptions.Logger.Infof("extra_arguments '%v' from child overriding parent", child.Name)
terragruntOptions.Logger.Debugf("extra_arguments '%v' from child overriding parent", child.Name)
result[parentExtraArgsWithSameName] = child
} else {
// If the parent does not contain an extra_arguments with the same name as the child
Expand Down
2 changes: 1 addition & 1 deletion configstack/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func resolveTerraformModule(terragruntConfigPath string, terragruntOptions *opti
return nil, err
}
if (terragruntConfig.Terraform == nil || terragruntConfig.Terraform.Source == "") && matches == nil {
terragruntOptions.Logger.Warningf("Module %s does not have an associated terraform configuration and will be skipped.", filepath.Dir(terragruntConfigPath))
terragruntOptions.Logger.Debugf("Module %s does not have an associated terraform configuration and will be skipped.", filepath.Dir(terragruntConfigPath))
return nil, nil
}

Expand Down
12 changes: 6 additions & 6 deletions configstack/running_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (module *runningModule) runModuleWhenReady() {
// Wait for all of this modules dependencies to finish executing. Return an error if any of those dependencies complete
// with an error. Return immediately if this module has no dependencies.
func (module *runningModule) waitForDependencies() error {
module.Module.TerragruntOptions.Logger.Noticef("Module %s must wait for %d dependencies to finish", module.Module.Path, len(module.Dependencies))
module.Module.TerragruntOptions.Logger.Debugf("Module %s must wait for %d dependencies to finish", module.Module.Path, len(module.Dependencies))
for len(module.Dependencies) > 0 {
doneDependency := <-module.DependencyDone
delete(module.Dependencies, doneDependency.Module.Path)
Expand All @@ -198,7 +198,7 @@ func (module *runningModule) waitForDependencies() error {
return DependencyFinishedWithError{module.Module, doneDependency.Module, doneDependency.Err}
}
} else {
module.Module.TerragruntOptions.Logger.Noticef("Dependency %s of module %s just finished successfully. Module %s must wait on %d more dependencies.", doneDependency.Module.Path, module.Module.Path, module.Module.Path, len(module.Dependencies))
module.Module.TerragruntOptions.Logger.Debugf("Dependency %s of module %s just finished successfully. Module %s must wait on %d more dependencies.", doneDependency.Module.Path, module.Module.Path, module.Module.Path, len(module.Dependencies))
}
}

Expand All @@ -210,10 +210,10 @@ func (module *runningModule) runNow() error {
module.Status = Running

if module.Module.AssumeAlreadyApplied {
module.Module.TerragruntOptions.Logger.Infof("Assuming module %s has already been applied and skipping it", module.Module.Path)
module.Module.TerragruntOptions.Logger.Debugf("Assuming module %s has already been applied and skipping it", module.Module.Path)
return nil
} else {
module.Module.TerragruntOptions.Logger.Noticef("Running module %s now", module.Module.Path)
module.Module.TerragruntOptions.Logger.Debugf("Running module %s now", module.Module.Path)
return module.Module.TerragruntOptions.RunTerragrunt(module.Module.TerragruntOptions)
}
}
Expand All @@ -223,7 +223,7 @@ var separator = strings.Repeat("-", 132)
// Record that a module has finished executing and notify all of this module's dependencies
func (module *runningModule) moduleFinished(moduleErr error) {
status := "successfully!"
logFinish := module.Module.TerragruntOptions.Logger.Noticef
logFinish := module.Module.TerragruntOptions.Logger.Infof
if moduleErr != nil {
status = fmt.Sprintf("with an error: %v", moduleErr)
logFinish = module.Module.TerragruntOptions.Logger.Errorf
Expand All @@ -238,7 +238,7 @@ func (module *runningModule) moduleFinished(moduleErr error) {
}
out := module.OutStream.String()
if out == "" {
module.Module.TerragruntOptions.Logger.Notice("No output")
module.Module.TerragruntOptions.Logger.Info("No output")
} else {
fmt.Fprintf(module.Writer, "%s\n%v\n\n%v\n", separator, util.GetPathRelativeToWorkingDir(module.Module.Path), module.OutStream.String())
}
Expand Down
10 changes: 5 additions & 5 deletions configstack/stack_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package configstack

import (
"fmt"
"github.com/gruntwork-io/terragrunt/options"
"github.com/gruntwork-io/terragrunt/shell"
"github.com/gruntwork-io/terragrunt/util"
"regexp"
"strconv"
"strings"

"github.com/gruntwork-io/terragrunt/options"
"github.com/gruntwork-io/terragrunt/shell"
"github.com/gruntwork-io/terragrunt/util"
)

// The returned information for each module
Expand Down Expand Up @@ -104,8 +105,7 @@ func warnAboutMissingDependencies(module TerraformModule, output string) {
if len(module.Dependencies) > 0 {
dependenciesMsg = fmt.Sprintf(" contains dependencies to %v and", module.Config.Dependencies.Paths)
}
module.TerragruntOptions.Logger.Warningf("%v%v refers to remote state "+
"you may have to apply your changes in the dependencies prior running terragrunt plan-all.\n",
module.TerragruntOptions.Logger.Warningf("%v%v refers to remote state, you may have to apply your changes in the dependencies prior running terragrunt plan-all.\n",
module.Path,
dependenciesMsg,
)
Expand Down
2 changes: 1 addition & 1 deletion options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (terragruntOptions *TerragruntOptions) SaveVariables() (err error) {
}

for file := range terragruntOptions.deferredSaveList {
terragruntOptions.Logger.Infof("Saving variables into %s", file)
terragruntOptions.Logger.Debug("Saving variables into", file)
var content []byte
switch strings.ToLower(filepath.Ext(file)) {
case ".yml", ".yaml":
Expand Down
4 changes: 2 additions & 2 deletions remote/remote_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ func shouldOverrideExistingRemoteState(existingBackend *TerraformBackend, remote
return strings.Join(result, "\n\t")
}

terragruntOptions.Logger.Warningf("Terraform remote state is already configured for backend %s", existingBackend.Type)
terragruntOptions.Logger.Warning("Terraform remote state is already configured for backend", existingBackend.Type)
prompt := fmt.Sprintf("\n Existing config:\n\t%v\n\n New config:\n\t%v\n\nOverwrite?", getValues(existingBackend.Config), getValues(remoteStateFromTerragruntConfig.Config))
return shell.PromptUserForYesNo(prompt, terragruntOptions)
}

terragruntOptions.Logger.Noticef("Remote state is already configured for backend %s", existingBackend.Type)
terragruntOptions.Logger.Info("Remote state is already configured for backend", existingBackend.Type)
return false, nil
}

Expand Down
Loading

0 comments on commit 40aee93

Please sign in to comment.