Skip to content

Commit

Permalink
Fix log-level not working properly (#568)
Browse files Browse the repository at this point in the history
* Fix log-level not working properly

* Address test failure
  • Loading branch information
james03160927 authored Aug 29, 2023
1 parent 6b41a50 commit 6887713
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion aws/resources/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion aws/resources/nat_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion aws/resources/opensearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions commands/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}

Expand Down
19 changes: 14 additions & 5 deletions logging/logger.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 6887713

Please sign in to comment.