diff --git a/api/client.go b/api/client.go index ce5f7798b291b..8674f7efcbdc6 100644 --- a/api/client.go +++ b/api/client.go @@ -97,6 +97,9 @@ type Config struct { // The CheckRetry function to use; a default is used if not provided CheckRetry retryablehttp.CheckRetry + // Logger is the leveled logger to provide to the retryable HTTP client. + Logger retryablehttp.LeveledLogger + // Limiter is the rate limiter used by the client. // If this pointer is nil, then there will be no limit set. // In contrast, if this pointer is set, even to an empty struct, @@ -477,6 +480,7 @@ func (c *Client) CloneConfig() *Config { newConfig.Timeout = c.config.Timeout newConfig.Backoff = c.config.Backoff newConfig.CheckRetry = c.config.CheckRetry + newConfig.Logger = c.config.Logger newConfig.Limiter = c.config.Limiter newConfig.OutputCurlString = c.config.OutputCurlString newConfig.SRVLookup = c.config.SRVLookup @@ -738,6 +742,15 @@ func (c *Client) SetBackoff(backoff retryablehttp.Backoff) { c.config.Backoff = backoff } +func (c *Client) SetLogger(logger retryablehttp.LeveledLogger) { + c.modifyLock.RLock() + defer c.modifyLock.RUnlock() + c.config.modifyLock.Lock() + defer c.config.modifyLock.Unlock() + + c.config.Logger = logger +} + // Clone creates a new client with the same configuration. Note that the same // underlying http.Client is used; modifying the client from more than one // goroutine at once may not be safe, so modify the client as needed and then @@ -761,6 +774,7 @@ func (c *Client) Clone() (*Client, error) { Timeout: config.Timeout, Backoff: config.Backoff, CheckRetry: config.CheckRetry, + Logger: config.Logger, Limiter: config.Limiter, OutputCurlString: config.OutputCurlString, AgentAddress: config.AgentAddress, @@ -865,6 +879,7 @@ func (c *Client) RawRequestWithContext(ctx context.Context, r *Request) (*Respon httpClient := c.config.HttpClient timeout := c.config.Timeout outputCurlString := c.config.OutputCurlString + logger := c.config.Logger c.config.modifyLock.RUnlock() c.modifyLock.RUnlock() @@ -924,6 +939,7 @@ START: RetryMax: maxRetries, Backoff: backoff, CheckRetry: checkRetry, + Logger: logger, ErrorHandler: retryablehttp.PassthroughErrorHandler, } diff --git a/api/client_test.go b/api/client_test.go index 87900856af24d..4fe356e1b85e4 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -13,6 +13,7 @@ import ( "testing" "time" + "github.com/hashicorp/go-hclog" "github.com/hashicorp/vault/sdk/helper/consts" ) @@ -427,6 +428,8 @@ func TestClone(t *testing.T) { } client1.SetCheckRetry(checkRetry) + client1.SetLogger(hclog.NewNullLogger()) + client1.SetLimiter(5.0, 10) client1.SetMaxRetries(5) client1.SetOutputCurlString(true) diff --git a/api/go.mod b/api/go.mod index 75bcfefe687ba..7e93c1c5684b8 100644 --- a/api/go.mod +++ b/api/go.mod @@ -9,6 +9,7 @@ require ( github.com/go-test/deep v1.0.2 github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-cleanhttp v0.5.1 + github.com/hashicorp/go-hclog v0.16.1 github.com/hashicorp/go-multierror v1.1.0 github.com/hashicorp/go-retryablehttp v0.6.6 github.com/hashicorp/go-rootcerts v1.0.2 diff --git a/api/go.sum b/api/go.sum index 749ad0d191d33..b6e144536fed5 100644 --- a/api/go.sum +++ b/api/go.sum @@ -100,8 +100,9 @@ github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVo github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQLReU= github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-hclog v0.16.1 h1:IVQwpTGNRRIHafnTs2dQLIk4ENtneRIEEJWOVDqz99o= +github.com/hashicorp/go-hclog v0.16.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.1.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-kms-wrapping/entropy v0.1.0/go.mod h1:d1g9WGtAunDNpek8jUIEJnBlbgKS1N2Q61QkHiZyR1g= diff --git a/go.mod b/go.mod index 555a6ffcc9041..25d02139d946c 100644 --- a/go.mod +++ b/go.mod @@ -62,7 +62,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/go-discover v0.0.0-20201029210230-738cb3105cd0 github.com/hashicorp/go-gcp-common v0.6.0 - github.com/hashicorp/go-hclog v0.16.0 + github.com/hashicorp/go-hclog v0.16.1 github.com/hashicorp/go-kms-wrapping v0.5.16 github.com/hashicorp/go-memdb v1.0.2 github.com/hashicorp/go-msgpack v1.1.5 // indirect diff --git a/go.sum b/go.sum index c0c0264982fbf..9301dea32f29f 100644 --- a/go.sum +++ b/go.sum @@ -560,6 +560,8 @@ github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39 github.com/hashicorp/go-hclog v0.15.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-hclog v0.16.0 h1:uCeOEwSWGMwhJUdpUjk+1cVKIEfGu2/1nFXukimi2MU= github.com/hashicorp/go-hclog v0.16.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-hclog v0.16.1 h1:IVQwpTGNRRIHafnTs2dQLIk4ENtneRIEEJWOVDqz99o= +github.com/hashicorp/go-hclog v0.16.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.1.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE= diff --git a/vendor/github.com/hashicorp/go-hclog/intlogger.go b/vendor/github.com/hashicorp/go-hclog/intlogger.go index f8f6ebd86a017..6099e67260e8e 100644 --- a/vendor/github.com/hashicorp/go-hclog/intlogger.go +++ b/vendor/github.com/hashicorp/go-hclog/intlogger.go @@ -124,7 +124,7 @@ func newLogger(opts *LoggerOptions) *intLogger { independentLevels: opts.IndependentLevels, } if opts.IncludeLocation { - l.callerOffset = offsetIntLogger + l.callerOffset = offsetIntLogger + opts.AdditionalLocationOffset } if l.json { diff --git a/vendor/github.com/hashicorp/go-hclog/logger.go b/vendor/github.com/hashicorp/go-hclog/logger.go index 83eafc152c681..7f36b1fd20f4a 100644 --- a/vendor/github.com/hashicorp/go-hclog/logger.go +++ b/vendor/github.com/hashicorp/go-hclog/logger.go @@ -235,6 +235,10 @@ type LoggerOptions struct { // Include file and line information in each log line IncludeLocation bool + // AdditionalLocationOffset is the number of additional stack levels to skip + // when finding the file and line information for the log line + AdditionalLocationOffset int + // The time format to use instead of the default TimeFormat string diff --git a/vendor/github.com/hashicorp/vault/api/client.go b/vendor/github.com/hashicorp/vault/api/client.go index ce5f7798b291b..8674f7efcbdc6 100644 --- a/vendor/github.com/hashicorp/vault/api/client.go +++ b/vendor/github.com/hashicorp/vault/api/client.go @@ -97,6 +97,9 @@ type Config struct { // The CheckRetry function to use; a default is used if not provided CheckRetry retryablehttp.CheckRetry + // Logger is the leveled logger to provide to the retryable HTTP client. + Logger retryablehttp.LeveledLogger + // Limiter is the rate limiter used by the client. // If this pointer is nil, then there will be no limit set. // In contrast, if this pointer is set, even to an empty struct, @@ -477,6 +480,7 @@ func (c *Client) CloneConfig() *Config { newConfig.Timeout = c.config.Timeout newConfig.Backoff = c.config.Backoff newConfig.CheckRetry = c.config.CheckRetry + newConfig.Logger = c.config.Logger newConfig.Limiter = c.config.Limiter newConfig.OutputCurlString = c.config.OutputCurlString newConfig.SRVLookup = c.config.SRVLookup @@ -738,6 +742,15 @@ func (c *Client) SetBackoff(backoff retryablehttp.Backoff) { c.config.Backoff = backoff } +func (c *Client) SetLogger(logger retryablehttp.LeveledLogger) { + c.modifyLock.RLock() + defer c.modifyLock.RUnlock() + c.config.modifyLock.Lock() + defer c.config.modifyLock.Unlock() + + c.config.Logger = logger +} + // Clone creates a new client with the same configuration. Note that the same // underlying http.Client is used; modifying the client from more than one // goroutine at once may not be safe, so modify the client as needed and then @@ -761,6 +774,7 @@ func (c *Client) Clone() (*Client, error) { Timeout: config.Timeout, Backoff: config.Backoff, CheckRetry: config.CheckRetry, + Logger: config.Logger, Limiter: config.Limiter, OutputCurlString: config.OutputCurlString, AgentAddress: config.AgentAddress, @@ -865,6 +879,7 @@ func (c *Client) RawRequestWithContext(ctx context.Context, r *Request) (*Respon httpClient := c.config.HttpClient timeout := c.config.Timeout outputCurlString := c.config.OutputCurlString + logger := c.config.Logger c.config.modifyLock.RUnlock() c.modifyLock.RUnlock() @@ -924,6 +939,7 @@ START: RetryMax: maxRetries, Backoff: backoff, CheckRetry: checkRetry, + Logger: logger, ErrorHandler: retryablehttp.PassthroughErrorHandler, } diff --git a/vendor/github.com/hashicorp/vault/api/go.mod b/vendor/github.com/hashicorp/vault/api/go.mod index 75bcfefe687ba..7e93c1c5684b8 100644 --- a/vendor/github.com/hashicorp/vault/api/go.mod +++ b/vendor/github.com/hashicorp/vault/api/go.mod @@ -9,6 +9,7 @@ require ( github.com/go-test/deep v1.0.2 github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-cleanhttp v0.5.1 + github.com/hashicorp/go-hclog v0.16.1 github.com/hashicorp/go-multierror v1.1.0 github.com/hashicorp/go-retryablehttp v0.6.6 github.com/hashicorp/go-rootcerts v1.0.2 diff --git a/vendor/github.com/hashicorp/vault/api/go.sum b/vendor/github.com/hashicorp/vault/api/go.sum index 749ad0d191d33..b6e144536fed5 100644 --- a/vendor/github.com/hashicorp/vault/api/go.sum +++ b/vendor/github.com/hashicorp/vault/api/go.sum @@ -100,8 +100,9 @@ github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVo github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQLReU= github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-hclog v0.16.1 h1:IVQwpTGNRRIHafnTs2dQLIk4ENtneRIEEJWOVDqz99o= +github.com/hashicorp/go-hclog v0.16.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.1.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-kms-wrapping/entropy v0.1.0/go.mod h1:d1g9WGtAunDNpek8jUIEJnBlbgKS1N2Q61QkHiZyR1g= diff --git a/vendor/modules.txt b/vendor/modules.txt index d00c1aed6aa3b..8eab0aa5d4fcd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -531,7 +531,7 @@ github.com/hashicorp/go-discover/provider/vsphere # github.com/hashicorp/go-gcp-common v0.6.0 ## explicit github.com/hashicorp/go-gcp-common/gcputil -# github.com/hashicorp/go-hclog v0.16.0 +# github.com/hashicorp/go-hclog v0.16.1 ## explicit github.com/hashicorp/go-hclog # github.com/hashicorp/go-immutable-radix v1.3.0