Skip to content

Commit

Permalink
WithLogger sets a new logger
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh committed Feb 28, 2022
1 parent 0f37e12 commit 631d7dc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ecr-login/ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,32 @@ type ECRHelper struct {

type Option func(*ECRHelper)

// WithClientFactory sets the ClientFactory used to make API requests.
func WithClientFactory(clientFactory api.ClientFactory) Option {
return func(e *ECRHelper) {
e.clientFactory = clientFactory
}
}

func WithLogOutput(w io.Writer) Option {
// WithLogger sets a new logger instance that writes to the given writer,
// instead of the default writer which writes to stderr.
//
// This can be useful if callers want to redirect logging emitted by this tool
// to another location.
func WithLogger(w io.Writer) Option {
return func(e *ECRHelper) {
e.logger.Out = w
logger := logrus.New()
logger.Out = w
e.logger = logger
}
}

// NewECRHelper returns a new ECRHelper with the given options to override
// default behavior.
func NewECRHelper(opts ...Option) *ECRHelper {
e := &ECRHelper{
clientFactory: api.DefaultClientFactory{},
logger: logrus.New(),
logger: logrus.StandardLogger(),
}
for _, o := range opts {
o(e)
Expand Down

0 comments on commit 631d7dc

Please sign in to comment.