@@ -200,10 +200,10 @@ func (logger *Logger) rotate() error {
200
200
return nil
201
201
}
202
202
203
- // toJSONString converts any object to a JSON string for logging purposes.
203
+ // ToJSONString converts any object to a JSON string for logging purposes.
204
204
// When the object contains json.RawMessage fields, they will be properly formatted
205
205
// instead of being shown as byte arrays. Falls back to %+v if JSON marshaling fails.
206
- func toJSONString (obj interface {}) string {
206
+ func ToJSONString (obj interface {}) string {
207
207
if obj == nil {
208
208
return "null"
209
209
}
@@ -219,31 +219,31 @@ func toJSONString(obj interface{}) string {
219
219
// Request logs a structured request.
220
220
func (logger * Logger ) Request (tag string , request interface {}, err error ) {
221
221
if err == nil {
222
- logger .Printf ("[%s] Received %T %s." , tag , request , toJSONString (request ))
222
+ logger .Printf ("[%s] Received %T %s." , tag , request , ToJSONString (request ))
223
223
} else {
224
- logger .Errorf ("[%s] Failed to decode %T %s %s." , tag , request , toJSONString (request ), err .Error ())
224
+ logger .Errorf ("[%s] Failed to decode %T %s %s." , tag , request , ToJSONString (request ), err .Error ())
225
225
}
226
226
}
227
227
228
228
// Response logs a structured response.
229
229
func (logger * Logger ) Response (tag string , response interface {}, returnCode int , returnStr string , err error ) {
230
230
if err == nil && returnCode == 0 {
231
- logger .Printf ("[%s] Sent %T %s." , tag , response , toJSONString (response ))
231
+ logger .Printf ("[%s] Sent %T %s." , tag , response , ToJSONString (response ))
232
232
} else if err != nil {
233
- logger .Errorf ("[%s] Code:%s, %s %s." , tag , returnStr , toJSONString (response ), err .Error ())
233
+ logger .Errorf ("[%s] Code:%s, %s %s." , tag , returnStr , ToJSONString (response ), err .Error ())
234
234
} else {
235
- logger .Errorf ("[%s] Code:%s, %s." , tag , returnStr , toJSONString (response ))
235
+ logger .Errorf ("[%s] Code:%s, %s." , tag , returnStr , ToJSONString (response ))
236
236
}
237
237
}
238
238
239
239
// ResponseEx logs a structured response and the request associate with it.
240
240
func (logger * Logger ) ResponseEx (tag string , request interface {}, response interface {}, returnCode int , returnStr string , err error ) {
241
241
if err == nil && returnCode == 0 {
242
- logger .Printf ("[%s] Sent %T %s %T %s." , tag , request , toJSONString (request ), response , toJSONString (response ))
242
+ logger .Printf ("[%s] Sent %T %s %T %s." , tag , request , ToJSONString (request ), response , ToJSONString (response ))
243
243
} else if err != nil {
244
- logger .Errorf ("[%s] Code:%s, %s, %s %s." , tag , returnStr , toJSONString (request ), toJSONString (response ), err .Error ())
244
+ logger .Errorf ("[%s] Code:%s, %s, %s %s." , tag , returnStr , ToJSONString (request ), ToJSONString (response ), err .Error ())
245
245
} else {
246
- logger .Errorf ("[%s] Code:%s, %s, %s." , tag , returnStr , toJSONString (request ), toJSONString (response ))
246
+ logger .Errorf ("[%s] Code:%s, %s, %s." , tag , returnStr , ToJSONString (request ), ToJSONString (response ))
247
247
}
248
248
}
249
249
0 commit comments