diff --git a/aws/resources/iam.go b/aws/resources/iam.go index efc71ba1..7eb87ccb 100644 --- a/aws/resources/iam.go +++ b/aws/resources/iam.go @@ -111,7 +111,7 @@ func (iu *IAMUsers) removeUserFromGroups(userName *string) error { func (iu *IAMUsers) deleteLoginProfile(userName *string) error { return retry.DoWithRetry( - logging.Logger, + logging.Logger.WithTime(time.Now()), "Delete Login Profile", 10, 2*time.Second, diff --git a/aws/resources/nat_gateway.go b/aws/resources/nat_gateway.go index 7c463e1b..9f4894b4 100644 --- a/aws/resources/nat_gateway.go +++ b/aws/resources/nat_gateway.go @@ -108,7 +108,7 @@ func (ngw *NatGateways) nukeAll(identifiers []*string) error { // Now wait until the NAT gateways are deleted err := retry.DoWithRetry( - logging.Logger, + logging.Logger.WithTime(time.Now()), "Waiting for all NAT gateways to be deleted.", // Wait a maximum of 5 minutes: 10 seconds in between, up to 30 times 30, 10*time.Second, diff --git a/aws/resources/opensearch.go b/aws/resources/opensearch.go index 63c2dc9b..120c4a17 100644 --- a/aws/resources/opensearch.go +++ b/aws/resources/opensearch.go @@ -180,7 +180,7 @@ func (osd *OpenSearchDomains) nukeAll(identifiers []*string) error { // Now wait until the OpenSearch Domains are deleted err := retry.DoWithRetry( - logging.Logger, + logging.Logger.WithTime(time.Now()), "Waiting for all OpenSearch Domains to be deleted.", // Wait a maximum of 5 minutes: 10 seconds in between, up to 30 times 30, 10*time.Second, diff --git a/commands/cli.go b/commands/cli.go index b1350457..a8a70a8b 100644 --- a/commands/cli.go +++ b/commands/cli.go @@ -24,7 +24,6 @@ import ( // CreateCli - Create the CLI app with all commands, flags, and usage text configured. func CreateCli(version string) *cli.App { app := cli.NewApp() - logging.InitLogger("cloud-nuke", version) _, disableTelemetryFlag := os.LookupEnv("DISABLE_TELEMETRY") if !disableTelemetryFlag { ui.WarningMessage("This program sends telemetry to Gruntwork. To disable, set DISABLE_TELEMETRY=true as an environment variable") @@ -189,7 +188,8 @@ func parseLogLevel(c *cli.Context) error { if err != nil { return fmt.Errorf("Invalid log level - %s - %s", logLevel, err) } - logging.Logger.Level = parsedLogLevel + logging.Logger.SetLevel(parsedLogLevel) + logging.Logger.Debugf("Setting log level to %s", parsedLogLevel.String()) return nil } diff --git a/logging/logger.go b/logging/logger.go index 2d7f7dad..6efb4bdf 100644 --- a/logging/logger.go +++ b/logging/logger.go @@ -1,10 +1,19 @@ package logging -import "github.com/gruntwork-io/go-commons/logging" +import ( + "github.com/sirupsen/logrus" + "os" +) -// Logger - Global logger variable -var Logger = logging.GetLogger("cloud-nuke", "") +var Logger = InitLogger() -func InitLogger(name string, version string) { - Logger = logging.GetLogger(name, version) +func InitLogger() *logrus.Logger { + logger := logrus.New() + + // Set the desired log level (e.g., Debug, Info, Warn, Error, etc.) + logger.SetLevel(logrus.InfoLevel) + + // You can also set the log output (e.g., os.Stdout, a file, etc.) + logger.SetOutput(os.Stdout) + return logger }