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

Fix log-level not working properly #568

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 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
5 changes: 3 additions & 2 deletions commands/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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)
logging.InitLogger()
_, 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 +189,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
18 changes: 13 additions & 5 deletions logging/logger.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
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 *logrus.Logger

func InitLogger(name string, version string) {
Logger = logging.GetLogger(name, version)
func InitLogger() {
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)
}