Skip to content

Commit 1ac6675

Browse files
committed
migrating to sugared logger
1 parent ded8d78 commit 1ac6675

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

httpclient/client.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ import (
1818
"github.com/deploymenttheory/go-api-http-client/redirecthandler"
1919
)
2020

21+
const ()
22+
2123
// TODO all struct comments
2224

2325
// Master struct/object
2426
type Client struct {
2527
// Config
26-
config ClientConfig
28+
config *ClientConfig
2729

2830
// Integration
2931
Integration *APIIntegration
@@ -92,20 +94,24 @@ type ClientConfig struct {
9294
}
9395

9496
// BuildClient creates a new HTTP client with the provided configuration.
95-
func (c ClientConfig) Build() (*Client, error) {
97+
func (c *ClientConfig) Build() (*Client, error) {
9698
if c.Sugar == nil {
9799
zapLogger, err := zap.NewProduction()
98100
if err != nil {
99101
return nil, err
100102
}
101103

102104
c.Sugar = zapLogger.Sugar()
105+
c.Sugar.Info("No logger provided. Defaulting to Sugared Zap Production Logger")
103106
}
104107

108+
c.Sugar.Debug("validating configuration")
109+
105110
err := c.validateClientConfig()
106111
if err != nil {
107112
return nil, fmt.Errorf("invalid configuration: %v", err)
108113
}
114+
c.Sugar.Debug("configuration valid")
109115

110116
httpClient := &http.Client{
111117
Timeout: c.CustomTimeout,
@@ -138,6 +144,7 @@ func (c ClientConfig) Build() (*Client, error) {
138144
}
139145

140146
if len(client.config.CustomCookies) > 0 {
147+
client.Sugar.Debug("setting custom cookies")
141148
client.loadCustomCookies()
142149
}
143150

httpclient/cookies.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func (c *Client) loadCustomCookies() error {
1818
}
1919

2020
c.http.Jar.SetCookies(cookieUrl, c.config.CustomCookies)
21+
c.Sugar.Debug("custom cookies set: %v", c.http.Jar.Cookies(cookieUrl))
2122

2223
return nil
2324
}

httpclient/headers.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@ package httpclient
33

44
import (
55
"net/http"
6-
7-
"go.uber.org/zap"
86
)
97

108
// CheckDeprecationHeader checks the response headers for the Deprecation header and logs a warning if present.
119
func (c *Client) CheckDeprecationHeader(resp *http.Response) {
1210
deprecationHeader := resp.Header.Get("Deprecation")
1311
if deprecationHeader != "" {
14-
c.Sugar.Warn("API endpoint is deprecated",
15-
zap.String("Date", deprecationHeader),
16-
zap.String("Endpoint", resp.Request.URL.String()),
17-
)
12+
c.Sugar.Warn("API endpoint is deprecated", deprecationHeader, resp.Request.URL.String())
1813
}
1914
}

0 commit comments

Comments
 (0)