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

Use a single logger instance #1612

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (terragruntOptions *TerragruntOptions) Clone(terragruntConfigPath string) *
NonInteractive: terragruntOptions.NonInteractive,
TerraformCliArgs: util.CloneStringList(terragruntOptions.TerraformCliArgs),
WorkingDir: workingDir,
Logger: util.CreateLogEntryWithWriter(terragruntOptions.ErrWriter, workingDir, terragruntOptions.LogLevel),
Logger: terragruntOptions.Logger.WithField("prefix", workingDir),
LogLevel: terragruntOptions.LogLevel,
Env: util.CloneStringMap(terragruntOptions.Env),
Source: terragruntOptions.Source,
Expand Down
14 changes: 0 additions & 14 deletions util/logger.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package util

import (
"fmt"
"io"
"os"

"github.com/hashicorp/hcl/v2"
Expand Down Expand Up @@ -48,18 +46,6 @@ func CreateLogEntry(prefix string, level logrus.Level) *logrus.Entry {
return logger.WithFields(fields)
}

// CreateLoggerWithWriter Create a logger around the given output stream and prefix
func CreateLogEntryWithWriter(writer io.Writer, prefix string, level logrus.Level) *logrus.Entry {
if prefix != "" {
prefix = fmt.Sprintf("[%s] ", prefix)
} else {
prefix = fmt.Sprintf("[terragrunt] %s", prefix)
}
logger := CreateLogEntry(prefix, level)
logger.Logger.SetOutput(writer)
return logger
}

// GetDiagnosticsWriter returns a hcl2 parsing diagnostics emitter for the current terminal.
func GetDiagnosticsWriter(parser *hclparse.Parser) hcl.DiagnosticWriter {
termColor := terminal.IsTerminal(int(os.Stderr.Fd()))
Expand Down