aws-sdk-go-v2 custom logger
Asked Answered
S

1

7

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?

Schlesien answered 29/1, 2022 at 10:25 Comment(0)
R
5

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),
    )
    ....
}
Ryon answered 29/1, 2022 at 10:55 Comment(1)
that's the missing link, smithy. I think syntax in how to satisfy something is also a bit tricky. Thanks!Schlesien

© 2022 - 2024 — McMap. All rights reserved.