Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

BugFix/log_aws_debug #119

Merged
merged 1 commit into from
Jul 20, 2021
Merged
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
15 changes: 15 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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...))
}
}