Skip to content

Commit af3384e

Browse files
committed
Allow logger injection.
1 parent 3513105 commit af3384e

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

awscommons/v2/auth.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/aws/aws-sdk-go-v2/aws"
77
"github.com/aws/aws-sdk-go-v2/config"
88
"github.com/gruntwork-io/go-commons/errors"
9+
"github.com/sirupsen/logrus"
910
)
1011

1112
const (
@@ -17,6 +18,8 @@ type Options struct {
1718
Region string
1819

1920
Context context.Context
21+
22+
Logger logrus.Entry
2023
}
2124

2225
// NewOptions will create a new aws.Options struct that provides reasonable defaults for unspecified values.

awscommons/v2/ecs.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
ecsTypes "github.com/aws/aws-sdk-go-v2/service/ecs/types"
1212
"github.com/gruntwork-io/go-commons/collections"
1313
"github.com/gruntwork-io/go-commons/errors"
14-
"github.com/gruntwork-io/go-commons/logging"
1514
"github.com/gruntwork-io/go-commons/retry"
1615
)
1716

@@ -29,7 +28,7 @@ func GetContainerInstanceArns(opts *Options, clusterName string) ([]string, erro
2928
return nil, err
3029
}
3130

32-
logger := logging.GetProjectLogger()
31+
logger := opts.Logger
3332
logger.Infof("Looking up Container Instance ARNs for ECS cluster %s", clusterName)
3433

3534
input := &ecs.ListContainerInstancesInput{Cluster: aws.String(clusterName)}
@@ -60,7 +59,7 @@ func StartDrainingContainerInstances(opts *Options, clusterName string, containe
6059
return err
6160
}
6261

63-
logger := logging.GetProjectLogger()
62+
logger := opts.Logger
6463
batchSize := 10
6564
numBatches := int(math.Ceil(float64(len(containerInstanceArns) / batchSize)))
6665

@@ -100,7 +99,7 @@ func WaitForContainerInstancesToDrain(opts *Options, clusterName string, contain
10099
return err
101100
}
102101

103-
logger := logging.GetProjectLogger()
102+
logger := opts.Logger
104103
logger.Infof("Checking if all ECS Tasks have been drained from the ECS Container Instances in Cluster %s.", clusterName)
105104

106105
batchSize := 100
@@ -133,7 +132,7 @@ func WaitForContainerInstancesToDrain(opts *Options, clusterName string, contain
133132
}
134133

135134
// Yay, all done.
136-
if drained, _ := allInstancesFullyDrained(responses); drained == true {
135+
if drained, _ := allInstancesFullyDrained(opts, responses); drained == true {
137136
logger.Infof("All container instances have been drained in Cluster %s!", clusterName)
138137
return nil
139138
}
@@ -164,24 +163,24 @@ func NewECSClient(opts *Options) (*ecs.Client, error) {
164163
return ecs.NewFromConfig(cfg), nil
165164
}
166165

167-
func allInstancesFullyDrained(responses []*ecs.DescribeContainerInstancesOutput) (bool, error) {
166+
func allInstancesFullyDrained(opts *Options, responses []*ecs.DescribeContainerInstancesOutput) (bool, error) {
168167
for _, response := range responses {
169168
instances := response.ContainerInstances
170169
if len(instances) == 0 {
171170
return false, errors.WithStackTrace(fmt.Errorf("querying DescribeContainerInstances returned no instances"))
172171
}
173172

174173
for _, instance := range instances {
175-
if !instanceFullyDrained(instance) {
174+
if !instanceFullyDrained(opts, instance) {
176175
return false, nil
177176
}
178177
}
179178
}
180179
return true, nil
181180
}
182181

183-
func instanceFullyDrained(instance ecsTypes.ContainerInstance) bool {
184-
logger := logging.GetProjectLogger()
182+
func instanceFullyDrained(opts *Options, instance ecsTypes.ContainerInstance) bool {
183+
logger := opts.Logger
185184
instanceArn := instance.ContainerInstanceArn
186185

187186
if *instance.Status == "ACTIVE" {

logging/logging.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ import (
99
var globalLogLevel = logrus.InfoLevel
1010
var globalLogLevelLock = sync.Mutex{}
1111

12-
// GetProjectLogger creates a new project logger
13-
func GetProjectLogger() *logrus.Entry {
14-
logger := GetLogger("")
15-
return logger.WithField("name", "go-commons")
16-
}
17-
1812
// GetLogger create a new logger with the given name
1913
func GetLogger(name string) *logrus.Logger {
2014
logger := logrus.New()

0 commit comments

Comments
 (0)