@@ -78,7 +78,7 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
78
78
79
79
if c .config .CustomTimeout > 0 {
80
80
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 ))
82
82
} else {
83
83
ctx = context .Background ()
84
84
cancel = func () {}
@@ -94,40 +94,41 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
94
94
var err error
95
95
body , contentType , err = createStreamingMultipartRequestBody (files , formDataFields , fileContentTypes , formDataPartHeaders , c .Sugar )
96
96
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 ))
98
98
} 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 ))
100
100
}
101
101
return err
102
102
}
103
103
104
104
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 ))
106
106
return nil , err
107
107
}
108
108
109
109
req , err := http .NewRequestWithContext (ctx , method , url , body )
110
110
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 ))
112
112
return nil , err
113
113
}
114
114
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 ))
116
116
117
117
(* c .Integration ).PrepRequestParamsAndAuth (req )
118
118
119
119
req .Header .Set ("Content-Type" , contentType )
120
120
121
121
startTime := time .Now ()
122
+
122
123
resp , requestErr := c .http .Do (req )
123
124
duration := time .Since (startTime )
124
125
125
126
if requestErr != nil {
126
- 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 ))
127
128
return nil , requestErr
128
129
}
129
130
130
- 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 ))
131
132
132
133
if resp .StatusCode >= 200 && resp .StatusCode < 300 {
133
134
return resp , response .HandleAPISuccessResponse (resp , out , c .Sugar )
@@ -164,28 +165,28 @@ func createStreamingMultipartRequestBody(files map[string][]string, formDataFiel
164
165
go func () {
165
166
defer func () {
166
167
if err := writer .Close (); err != nil {
167
- sugar .Error ("Failed to close multipart writer" , zap .Error (err ))
168
+ sugar .Errorw ("Failed to close multipart writer" , zap .Error (err ))
168
169
}
169
170
if err := pw .Close (); err != nil {
170
- sugar .Error ("Failed to close pipe writer" , zap .Error (err ))
171
+ sugar .Errorw ("Failed to close pipe writer" , zap .Error (err ))
171
172
}
172
173
}()
173
174
174
175
for fieldName , filePaths := range files {
175
176
for _ , filePath := range filePaths {
176
- sugar .Debug ("Adding file part" , zap .String ("field_name" , fieldName ), zap .String ("file_path" , filePath ))
177
+ sugar .Debugw ("Adding file part" , zap .String ("field_name" , fieldName ), zap .String ("file_path" , filePath ))
177
178
if err := addFilePart (writer , fieldName , filePath , fileContentTypes , formDataPartHeaders , sugar ); err != nil {
178
- sugar .Error ("Failed to add file part" , zap .Error (err ))
179
+ sugar .Errorw ("Failed to add file part" , zap .Error (err ))
179
180
pw .CloseWithError (err )
180
181
return
181
182
}
182
183
}
183
184
}
184
185
185
186
for key , val := range formDataFields {
186
- sugar .Debug ("Adding form field" , zap .String ("field_name" , key ), zap .String ("field_value" , val ))
187
+ sugar .Debugw ("Adding form field" , zap .String ("field_name" , key ), zap .String ("field_value" , val ))
187
188
if err := addFormField (writer , key , val , sugar ); err != nil {
188
- sugar .Error ("Failed to add form field" , zap .Error (err ))
189
+ sugar .Errorw ("Failed to add form field" , zap .Error (err ))
189
190
pw .CloseWithError (err )
190
191
return
191
192
}
@@ -214,7 +215,7 @@ func createStreamingMultipartRequestBody(files map[string][]string, formDataFiel
214
215
func addFilePart (writer * multipart.Writer , fieldName , filePath string , fileContentTypes map [string ]string , formDataPartHeaders map [string ]http.Header , sugar * zap.SugaredLogger ) error {
215
216
file , err := os .Open (filePath )
216
217
if err != nil {
217
- sugar .Error ("Failed to open file" , zap .String ("filePath" , filePath ), zap .Error (err ))
218
+ sugar .Errorw ("Failed to open file" , zap .String ("filePath" , filePath ), zap .Error (err ))
218
219
return err
219
220
}
220
221
defer file .Close ()
@@ -229,7 +230,7 @@ func addFilePart(writer *multipart.Writer, fieldName, filePath string, fileConte
229
230
230
231
part , err := writer .CreatePart (header )
231
232
if err != nil {
232
- sugar .Error ("Failed to create form file part" , zap .String ("fieldName" , fieldName ), zap .Error (err ))
233
+ sugar .Errorw ("Failed to create form file part" , zap .String ("fieldName" , fieldName ), zap .Error (err ))
233
234
return err
234
235
}
235
236
@@ -238,14 +239,14 @@ func addFilePart(writer *multipart.Writer, fieldName, filePath string, fileConte
238
239
239
240
fileSize , err := file .Stat ()
240
241
if err != nil {
241
- sugar .Error ("Failed to get file info" , zap .String ("filePath" , filePath ), zap .Error (err ))
242
+ sugar .Errorw ("Failed to get file info" , zap .String ("filePath" , filePath ), zap .Error (err ))
242
243
return err
243
244
}
244
245
245
246
progressLogger := logUploadProgress (file , fileSize .Size (), sugar )
246
247
uploadState := & UploadState {}
247
248
if err := chunkFileUpload (file , encoder , progressLogger , uploadState , sugar ); err != nil {
248
- sugar .Error ("Failed to copy file content" , zap .String ("filePath" , filePath ), zap .Error (err ))
249
+ sugar .Errorw ("Failed to copy file content" , zap .String ("filePath" , filePath ), zap .Error (err ))
249
250
return err
250
251
}
251
252
@@ -267,11 +268,11 @@ func addFilePart(writer *multipart.Writer, fieldName, filePath string, fileConte
267
268
func addFormField (writer * multipart.Writer , key , val string , sugar * zap.SugaredLogger ) error {
268
269
fieldWriter , err := writer .CreateFormField (key )
269
270
if err != nil {
270
- 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 ))
271
272
return err
272
273
}
273
274
if _ , err := fieldWriter .Write ([]byte (val )); err != nil {
274
- 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 ))
275
276
return err
276
277
}
277
278
return nil
@@ -362,7 +363,7 @@ func chunkFileUpload(file *os.File, writer io.Writer, updateProgress func(int64)
362
363
363
364
if chunkWritten >= chunkSize {
364
365
currentChunk ++
365
- sugar .Debug ("File Upload Chunk Sent" ,
366
+ sugar .Debugw ("File Upload Chunk Sent" ,
366
367
zap .String ("file_name" , fileName ),
367
368
zap .Int64 ("chunk_number" , currentChunk ),
368
369
zap .Int64 ("total_chunks" , totalChunks ),
@@ -375,7 +376,7 @@ func chunkFileUpload(file *os.File, writer io.Writer, updateProgress func(int64)
375
376
// sugar any remaining bytes that were written but didn't reach the sugar threshold
376
377
if chunkWritten > 0 {
377
378
currentChunk ++
378
- sugar .Debug ("Final Upload Chunk Sent" ,
379
+ sugar .Debugw ("Final Upload Chunk Sent" ,
379
380
zap .String ("file_name" , fileName ),
380
381
zap .Int64 ("chunk_number" , currentChunk ),
381
382
zap .Int64 ("total_chunks" , totalChunks ),
@@ -411,7 +412,7 @@ func logUploadProgress(file *os.File, fileSize int64, sugar *zap.SugaredLogger)
411
412
if percentage >= lastLoggedPercentage + logInterval {
412
413
elapsedTime := time .Since (startTime )
413
414
414
- sugar .Info ("Upload progress" ,
415
+ sugar .Infow ("Upload progress" ,
415
416
zap .String ("file_name" , fileName ),
416
417
zap .Float64 ("uploaded_MB's" , float64 (uploaded )/ 1048576 ), // sugar in MB (1024 * 1024)
417
418
zap .Float64 ("total_filesize_in_MB" , float64 (fileSize )/ 1048576 ),
0 commit comments