From 6747ea00aefd70a0400b4a6f2b49ff74dfd9020d Mon Sep 17 00:00:00 2001 From: roneli <38083777+roneli@users.noreply.github.com> Date: Tue, 20 Jul 2021 16:40:20 +0300 Subject: [PATCH] override aws logger in aws debug flag on --- client/client.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client/client.go b/client/client.go index 5d79c6715..3e8730e13 100644 --- a/client/client.go +++ b/client/client.go @@ -5,6 +5,8 @@ import ( "fmt" "time" + "github.com/aws/smithy-go/logging" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/aws/retry" "github.com/aws/aws-sdk-go-v2/config" @@ -281,6 +283,7 @@ func Configure(logger hclog.Logger, providerConfig interface{}) (schema.ClientMe if awsConfig.AWSDebug { awsCfg.ClientLogMode = aws.LogRequest | aws.LogResponse | aws.LogRetries + awsCfg.Logger = AwsLogger{logger} } svc := sts.NewFromConfig(awsCfg) output, err := svc.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{}, func(o *sts.Options) { @@ -378,3 +381,15 @@ func filterDisabledRegions(regions []string, enabledRegions []types.Region) []st } return filteredRegions } + +type AwsLogger struct { + l hclog.Logger +} + +func (a AwsLogger) Logf(classification logging.Classification, format string, v ...interface{}) { + if classification == logging.Warn { + a.l.Warn(fmt.Sprintf(format, v...)) + } else { + a.l.Debug(fmt.Sprintf(format, v...)) + } +}