6

With v1 of the SDK i could use logrus for my custom logger, like:

    Logger: aws.LoggerFunc(func(args ...interface{}) {
        log.WithField("process", "s3").Debug(args...)
    }),

This has changed with sdk v2, https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/logging/

It seems i need to use logging.logger as per https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/config#WithLogger

I'm having a hard time using logrus for this purpose, can anyone suggest what i need to do here?

Rygo
  • 159
  • 1
  • 8

1 Answers1

4

It seems that sdk v2 offers a func wrapper to satisfy logging.logger:


import (
   ...
   "github.com/aws/aws-sdk-go-v2/config"
   "github.com/aws/smithy-go/logging"
   log "github.com/sirupsen/logrus"
)

func main() {
    
    logger := logging.LoggerFunc(func(classification logging.Classification, format string, v ...interface{}) {
        // your custom logging 
        log.WithField("process", "s3").Debug(v...)
    })

    cfg, err := config.LoadDefaultConfig(
        context.TODO(),
        ...
        config.WithLogger(logger),
    )
    ....
}
reda la
  • 801
  • 1
  • 6
  • 10
  • that's the missing link, smithy. I think syntax in how to satisfy something is also a bit tricky. Thanks! – Rygo Jan 29 '22 at 15:46