From 1ac66757022094e2bdf900e6598bf91f7310592c Mon Sep 17 00:00:00 2001 From: Joseph Little Date: Tue, 2 Jul 2024 13:12:50 +0100 Subject: [PATCH] migrating to sugared logger --- httpclient/client.go | 11 +++++++++-- httpclient/cookies.go | 1 + httpclient/headers.go | 7 +------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/httpclient/client.go b/httpclient/client.go index 4152f63..c5468e7 100644 --- a/httpclient/client.go +++ b/httpclient/client.go @@ -18,12 +18,14 @@ import ( "github.com/deploymenttheory/go-api-http-client/redirecthandler" ) +const () + // TODO all struct comments // Master struct/object type Client struct { // Config - config ClientConfig + config *ClientConfig // Integration Integration *APIIntegration @@ -92,7 +94,7 @@ type ClientConfig struct { } // BuildClient creates a new HTTP client with the provided configuration. -func (c ClientConfig) Build() (*Client, error) { +func (c *ClientConfig) Build() (*Client, error) { if c.Sugar == nil { zapLogger, err := zap.NewProduction() if err != nil { @@ -100,12 +102,16 @@ func (c ClientConfig) Build() (*Client, error) { } c.Sugar = zapLogger.Sugar() + c.Sugar.Info("No logger provided. Defaulting to Sugared Zap Production Logger") } + c.Sugar.Debug("validating configuration") + err := c.validateClientConfig() if err != nil { return nil, fmt.Errorf("invalid configuration: %v", err) } + c.Sugar.Debug("configuration valid") httpClient := &http.Client{ Timeout: c.CustomTimeout, @@ -138,6 +144,7 @@ func (c ClientConfig) Build() (*Client, error) { } if len(client.config.CustomCookies) > 0 { + client.Sugar.Debug("setting custom cookies") client.loadCustomCookies() } diff --git a/httpclient/cookies.go b/httpclient/cookies.go index 923c0b1..6a20bf2 100644 --- a/httpclient/cookies.go +++ b/httpclient/cookies.go @@ -18,6 +18,7 @@ func (c *Client) loadCustomCookies() error { } c.http.Jar.SetCookies(cookieUrl, c.config.CustomCookies) + c.Sugar.Debug("custom cookies set: %v", c.http.Jar.Cookies(cookieUrl)) return nil } diff --git a/httpclient/headers.go b/httpclient/headers.go index d57910b..34b77fc 100644 --- a/httpclient/headers.go +++ b/httpclient/headers.go @@ -3,17 +3,12 @@ package httpclient import ( "net/http" - - "go.uber.org/zap" ) // CheckDeprecationHeader checks the response headers for the Deprecation header and logs a warning if present. func (c *Client) CheckDeprecationHeader(resp *http.Response) { deprecationHeader := resp.Header.Get("Deprecation") if deprecationHeader != "" { - c.Sugar.Warn("API endpoint is deprecated", - zap.String("Date", deprecationHeader), - zap.String("Endpoint", resp.Request.URL.String()), - ) + c.Sugar.Warn("API endpoint is deprecated", deprecationHeader, resp.Request.URL.String()) } }