Logging

Using Logging facilities for debugging SDK requests.

The AWS SDK for Go V2 has logging facilities available that allow your application to enable debugging information for debugging and diagnosing request issues or failures. The Logger interface and ClientLogMode are the main components available to you for determining how and what should be logged by clients.

Logger

When constructing an Config using LoadDefaultConfig a default Logger is configured to send log messages to the process’ standard error (stderr). A custom logger that satisfies the Logger interface can be passed as an argument to LoadDefaultConfig by wrapping it with config.WithLogger.

For example to configure our clients to use our applicationLogger:

cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithLogger(applicationLogger))

Now clients configured using the constructed aws.Config will send log messages to applicationLogger.

Context-Aware Loggers

A Logger implementation may implement the optional ContextLogger interface. Loggers that implement this interface will have their WithContext methods invoked with the current context. This allows your logging implementations to return a new Logger that can write additional logging metadata based on values present in the context.

ClientLogMode

By default, service clients do not produce log messages. To configure clients to send log messages for debugging purposes, use the ClientLogMode member on Config. ClientLogMode can be set to enable debugging messaging for:

  • Signature Version 4 (SigV4) Signing
  • Request Retries
  • HTTP Requests
  • HTTP Responses

For example to enable logging of HTTP requests and retries:

cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithClientLogMode(aws.LogRetries | aws.LogRequest))

See ClientLogMode for the different client log modes available.