gologrusaws-sdk-go-v2

aws-sdk-go-v2 custom logger


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?


Solution

  • 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),
        )
        ....
    }