package web

import (
	"fmt"

	"github.com/hashicorp/go-retryablehttp"
	"github.com/sirupsen/logrus"
)

type customLeveledLogger struct {
	retryablehttp.Logger
}

func (l customLeveledLogger) Printf(msg string, args ...interface{}) {
	logrus.Debugf(fmt.Sprintf(msg, args...))
}

// NewHTTPRetryClient instantiates a new http client with retries baked in
func NewHTTPRetryClient() *retryablehttp.Client {
	retryClient := retryablehttp.NewClient()
	retryClient.Logger = customLeveledLogger{}
	return retryClient
}