src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

logger.go (1045B)


      1 package waiter
      2 
      3 import (
      4 	"context"
      5 	"fmt"
      6 
      7 	"github.com/aws/smithy-go/logging"
      8 	"github.com/aws/smithy-go/middleware"
      9 )
     10 
     11 // Logger is the Logger middleware used by the waiter to log an attempt
     12 type Logger struct {
     13 	// Attempt is the current attempt to be logged
     14 	Attempt int64
     15 }
     16 
     17 // ID representing the Logger middleware
     18 func (*Logger) ID() string {
     19 	return "WaiterLogger"
     20 }
     21 
     22 // HandleInitialize performs handling of request in initialize stack step
     23 func (m *Logger) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
     24 	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
     25 ) {
     26 	logger := middleware.GetLogger(ctx)
     27 
     28 	logger.Logf(logging.Debug, fmt.Sprintf("attempting waiter request, attempt count: %d", m.Attempt))
     29 
     30 	return next.HandleInitialize(ctx, in)
     31 }
     32 
     33 // AddLogger is a helper util to add waiter logger after `SetLogger` middleware in
     34 func (m Logger) AddLogger(stack *middleware.Stack) error {
     35 	return stack.Initialize.Insert(&m, "SetLogger", middleware.After)
     36 }