Skip to content

Commit 82a9733

Browse files
committed
improved logging formatting.
1 parent 53e8676 commit 82a9733

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

httpclient/multipartrequest.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
7878

7979
if c.config.CustomTimeout > 0 {
8080
ctx, cancel = context.WithTimeout(context.Background(), c.config.CustomTimeout)
81-
c.Sugar.Info("Using timeout context for multipart request", zap.Duration("custom_timeout_seconds", c.config.CustomTimeout))
81+
c.Sugar.Infow("Using timeout context for multipart request", zap.Duration("custom_timeout_seconds", c.config.CustomTimeout))
8282
} else {
8383
ctx = context.Background()
8484
cancel = func() {}
@@ -94,25 +94,25 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
9494
var err error
9595
body, contentType, err = createStreamingMultipartRequestBody(files, formDataFields, fileContentTypes, formDataPartHeaders, c.Sugar)
9696
if err != nil {
97-
c.Sugar.Error("Failed to create streaming multipart request body", zap.Error(err))
97+
c.Sugar.Errorw("Failed to create streaming multipart request body", zap.Error(err))
9898
} else {
99-
c.Sugar.Info("Successfully created streaming multipart request body", zap.String("content_type", contentType))
99+
c.Sugar.Infow("Successfully created streaming multipart request body", zap.String("content_type", contentType))
100100
}
101101
return err
102102
}
103103

104104
if err := createBody(); err != nil {
105-
c.Sugar.Error("Failed to create streaming multipart request body", zap.Error(err))
105+
c.Sugar.Errorw("Failed to create streaming multipart request body", zap.Error(err))
106106
return nil, err
107107
}
108108

109109
req, err := http.NewRequestWithContext(ctx, method, url, body)
110110
if err != nil {
111-
c.Sugar.Error("Failed to create HTTP request", zap.Error(err))
111+
c.Sugar.Errorw("Failed to create HTTP request", zap.Error(err))
112112
return nil, err
113113
}
114114

115-
c.Sugar.Info("Created HTTP Multipart request", zap.String("method", method), zap.String("url", url), zap.String("content_type", contentType))
115+
c.Sugar.Infow("Created HTTP Multipart request", zap.String("method", method), zap.String("url", url), zap.String("content_type", contentType))
116116

117117
(*c.Integration).PrepRequestParamsAndAuth(req)
118118

@@ -124,11 +124,11 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
124124
duration := time.Since(startTime)
125125

126126
if requestErr != nil {
127-
c.Sugar.Error("Failed to send request", zap.String("method", method), zap.String("endpoint", endpoint), zap.Error(requestErr))
127+
c.Sugar.Errorw("Failed to send request", zap.String("method", method), zap.String("endpoint", endpoint), zap.Error(requestErr))
128128
return nil, requestErr
129129
}
130130

131-
c.Sugar.Debug("Request sent successfully", zap.String("method", method), zap.String("endpoint", endpoint), zap.Int("status_code", resp.StatusCode), zap.Duration("duration", duration))
131+
c.Sugar.Debugw("Request sent successfully", zap.String("method", method), zap.String("endpoint", endpoint), zap.Int("status_code", resp.StatusCode), zap.Duration("duration", duration))
132132

133133
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
134134
return resp, response.HandleAPISuccessResponse(resp, out, c.Sugar)
@@ -268,11 +268,11 @@ func addFilePart(writer *multipart.Writer, fieldName, filePath string, fileConte
268268
func addFormField(writer *multipart.Writer, key, val string, sugar *zap.SugaredLogger) error {
269269
fieldWriter, err := writer.CreateFormField(key)
270270
if err != nil {
271-
sugar.Error("Failed to create form field", zap.String("key", key), zap.Error(err))
271+
sugar.Errorw("Failed to create form field", zap.String("key", key), zap.Error(err))
272272
return err
273273
}
274274
if _, err := fieldWriter.Write([]byte(val)); err != nil {
275-
sugar.Error("Failed to write form field", zap.String("key", key), zap.Error(err))
275+
sugar.Errorw("Failed to write form field", zap.String("key", key), zap.Error(err))
276276
return err
277277
}
278278
return nil
@@ -363,7 +363,7 @@ func chunkFileUpload(file *os.File, writer io.Writer, updateProgress func(int64)
363363

364364
if chunkWritten >= chunkSize {
365365
currentChunk++
366-
sugar.Debug("File Upload Chunk Sent",
366+
sugar.Debugw("File Upload Chunk Sent",
367367
zap.String("file_name", fileName),
368368
zap.Int64("chunk_number", currentChunk),
369369
zap.Int64("total_chunks", totalChunks),
@@ -376,7 +376,7 @@ func chunkFileUpload(file *os.File, writer io.Writer, updateProgress func(int64)
376376
// sugar any remaining bytes that were written but didn't reach the sugar threshold
377377
if chunkWritten > 0 {
378378
currentChunk++
379-
sugar.Debug("Final Upload Chunk Sent",
379+
sugar.Debugw("Final Upload Chunk Sent",
380380
zap.String("file_name", fileName),
381381
zap.Int64("chunk_number", currentChunk),
382382
zap.Int64("total_chunks", totalChunks),
@@ -412,7 +412,7 @@ func logUploadProgress(file *os.File, fileSize int64, sugar *zap.SugaredLogger)
412412
if percentage >= lastLoggedPercentage+logInterval {
413413
elapsedTime := time.Since(startTime)
414414

415-
sugar.Info("Upload progress",
415+
sugar.Infow("Upload progress",
416416
zap.String("file_name", fileName),
417417
zap.Float64("uploaded_MB's", float64(uploaded)/1048576), // sugar in MB (1024 * 1024)
418418
zap.Float64("total_filesize_in_MB", float64(fileSize)/1048576),

0 commit comments

Comments
 (0)